|
i use ATL create a COM.
in IDL:
typedef
[
uuid(C21871A0-33EB-11D4-A13A-BE2573A1120F),
version(1.0),
helpstring("A Demo UDT variable")
]
struct UDTVariable
{
[helpstring("Name of the variable")] BSTR Name;
[helpstring("Value of the variable")] long Value;
[helpstring("Special case variant")] VARIANT Special;
[helpstring("point of pValue")] int *pVal;
} UDTVariable;
interface IImplementable : IDispatch
{
[id(1), helpstring("method GetUDTSequence")] HRESULT GetUDTSequence([in] long start, [in] long length, [out] SAFEARRAY(UDTVariable) *SequenceArr);
[id(2), helpstring("method GetOtherArray")] HRESULT GetOtherArray([out] UDTVariable** pData);
[id(3), helpstring("method GetData")] HRESULT GetData([out] short* pLength, [out] short* pData);
};
in ATL code:
public:
STDMETHOD(GetData)(/*[out]*/ short* pLength, /*[out]*/ short* pData);
STDMETHOD(GetOtherArray)(/*[out]*/ UDTVariable** pData);
STDMETHOD(GetUDTSequence)(/*[in]*/ long start, /*[in]*/ long length, /*[out]*/ SAFEARRAY **SequenceArr);
When i add reference of above COM, the signature will be create autolly:
[DispId(3)]
public virtual void GetData(out short pLength, out short pData);
[DispId(2)]
public virtual void GetOtherArray(IntPtr pData);
[DispId(1)]
public virtual void GetUDTSequence(int start, int length, out Array SequenceArr);
Question1:
About the fuction of GetData, if the data will be send to C#, the data will be movable? If it is movable, how let it fixed?
Question2:
how can I use the function : public virtual void GetUDTSequence(int start, int length, out Array SequenceArr) in C#?
I can't create a instance of Array becaust it is a abstract class.
Question3:how can I use the function : STDMETHOD(GetOtherArray)(/*[out]*/ UDTVariable** pData) in C#?
When I use:
UDTVariable* otherUDTArray;
The compiler tell me: Can't take address of ,get the size of, or declare a pointer to a managed type UDTVariable
Can you help me?
-- modified at 4:08 Wednesday 7th February, 2007
-- modified at 4:10 Wednesday 7th February, 2007
Human knowledge belongs to the world.
|
|
|
|
|
sunssuns wrote: how let it fixed?
You can use the C# fixed keyword. More info here[^].
sunssuns wrote: I can't create a instance of Array becaust it is a abstract class.
Not sure, but have you tried an object[] ?
sunssuns wrote: how can I use the function : STDMETHOD(GetOtherArray)(/*[out]*/ UDTVariable** pData) in C#?
First, make sure UDTVariable is a COM type or interface defined in C# or in some .NET assembly, so that .NET can know about it. Secondly, once in place, you should be able to call the method like this:
UDTVariable instance;
GetOtherArray(out instance)
|
|
|
|
|
Dear Judah Himango,
Judah Himango wrote: sunssuns wrote:
I can't create a instance of Array becaust it is a abstract class.
Not sure, but have you tried an object[] ?
I tried, but compiler tell me there is an error:
The best overloaded method match for 'SERVERLib.ImplementableClass.GetUDTSequence(int, int, out System.Array)' has some invalid arguments
Human knowledge belongs to the world.
|
|
|
|
|
Try this:
Array objects = new object[];
GetUDTSequence(int, int, out objects);
|
|
|
|
|
Yeah,
You are right.
But I need the following array:
UDTVariable[] UDTArray = new UDTVariable[length];
How can I convert Array[] to UDTVariable[]?
Human knowledge belongs to the world.
|
|
|
|
|
sunssuns wrote: How can I convert Array[] to UDTVariable[]?
Try the ancient manual way:
Array objects = new object[];
GetUDTSequence(int, int, out objects);
UDTVariable[] typedArray = new UDTVariable[objects.Length];
for(int i = 0; i < objects.Length; i++)
{
typedArray[i] = (UDTVariable)objects[i];
}
That work for ya?
|
|
|
|
|
I code like you told me:
Array objects = new object[length];
UDTVariable[] UDTArray = new UDTVariable[length];
aImplementableClass.GetUDTSequence(start, length, out objects
for (int i = 0; i < objects.Length; i++)
{
UDTArray[i] = (UDTVariable)objects[i];
}
but compiler tell me:
Cannot apply indexing with [] to an expression of type 'System.Array'
Human knowledge belongs to the world.
|
|
|
|
|
Array objects = new object[length];
UDTVariable[] UDTArray = new UDTVariable[length];
aImplementableClass.GetUDTSequence(start, length, out objects);
object[] typedObjects = (object[])objects;
for (int i = 0; i < typedObjects.Length; i++)
{
UDTArray[i] = (UDTVariable)typedObjects[i];
}
|
|
|
|
|
Hi ..
I am using public static variables throughout my application..
so how to release or dispose those variables on web application exit...
thank u..
|
|
|
|
|
It doesn't matter, they won't leak for long, will they ?
If you have stuff with handles you want released, do it in the OnClose of your main form.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi
I am coverting a report made in Access Application which contains subreports within subreports.The nesting is upto five levels deep.As Crystal reports do not allow adding of subreports within subreports,how do i deal with it.
Is there some other way to deal with the problem.Any suggestions and help will be appreciated.
Regards
Shaurya
|
|
|
|
|
Hi Shaurya
A quick google search reveals this article[^]. Hopefully it points you in the right direction.
|
|
|
|
|
I start leaning language C#, everybody hepl me?
I should begining step how? thank you very much!
thuylieu1905
|
|
|
|
|
|
Start by an english book first than go and get a C# book.
|
|
|
|
|
bitter truth
most e-books are in english..
life is study!!!
|
|
|
|
|
A beginners book, then work through examples on this site and ask questions here.
Try to get a C# language book, then a book that works with windows forms after that. A book that tells you where to click so the designer writes code for you, is useless.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
hello there buddy!
Welcome to the world of C#!
Get a book on C# language, and start working on examples.
Think of something innovative and try implementing it.
Good always wins over Evil
|
|
|
|
|
I start leaning language C#, everybody hepl me?
I should begining step how? thank you very much!
|
|
|
|
|
wrong forum... this is more for people who already work something with c# for complete begin get good book... almost any will do good job...
|
|
|
|
|
Hi,
this is my first question on CodeProject; its about Visual Designer.
Say I want to have a Panel and a PictureBox in the Form, no problem.
Now a Button in that Panel, no problem, just click in the Panel and drag a Button.
Now a Label in that PictureBox, Designer does not do that, even when I click inside
the PictureBox, the Label gets added to the Form, not to the PictureBox
(code checked: parent is Form, location is Form relative).
Also not working is Button in Button.
Is there a way to do these with Designer, i.e. without changing the code manually ?
If it is impossible for some Controls, which are they ? How can one recognize them ?
I am using both Visual 7.1 and 8.0 (in case it would be different).
TIA
-- modified at 20:38 Sunday 4th February, 2007
Luc Pattyn
|
|
|
|
|
I only VS .net
Some controls are not containers.
|
|
|
|
|
Luc Pattyn wrote: If it is impossible for some Controls, which are they ? How can one recognize them ?
I think you cannot recognize them. For example, the GroupBox and PictureBox are both direct inheritors of Control , but a dragged control is only added to the group box. So the designer is obviously following his own logic where it is sensible to add the dragged control to the form or the control it was dragged to, respectively.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hello Luc,
Isn't the interface "IContainer" responsible for that behavior?
All the best,
Martin
-- modified at 8:45 Monday 5th February, 2007
|
|
|
|
|
i'm using devenv to compile projects
say
Process.start("devenv",@"<solution> /build Debug ........... /out C:\BuildLog.txt");
the next piece of code is:
StreamReader sr = new StreamReader("C:\\BuildLog.txt");
string line;
while((line = sr.ReadLine()) != null)
{
LogText += line;
}
this throws a filenotfound exception the first time. on running the application again, it finds the file and displays its contents too...
the file gets appended with every run. but on reading it thru this code it does not read the latest chunks written to file.
for eg say
the file contains
abc
xyz
def
the file reads only abc xyz
and the next time it runs it reads abc xyz as well as def... but by then.... more chunks r appended.
Kindly help.
thanks in advance.
|
|
|
|
|