Link to home
Start Free TrialLog in
Avatar of Dak_Programmer
Dak_Programmer

asked on

How do I pass structures (UDT's) over a com interface

How can I pass structures over a com interface... I am looking for a good example....
Avatar of jkr
jkr
Flag of Germany image

Avatar of Dak_Programmer
Dak_Programmer

ASKER

Yeah that works fine for vb -- but for Visual C++ it seems that it takes more work than that...

I would really appreciate a working example that works for both VB and VC++.
>>Yeah that works fine for vb

Err, scroll down - the article uses VC++...
what is pInterface in their code?
>>what is pInterface in their code?

The pointer to the COM interface.
I could really use a real compilable example -- rather than just some code that is scratched in various portions in an article... hence the reason for the high point total
I could really use a real compilable example -- rather than just some code that is scratched in various portions in an article... hence the reason for the high point total
Please give your interface definition and structure which you want to pass.And tell me the direction of the passing, pass into the interface or return from the interface or both.
ok well the project I am working on is a COM dll that handles communication over a serial port using a proprietary protocol... this protocol returns response structures..


these structures are usually of the form:

struct resp_struct
{
   byte byCommand;
   byte byError;
   byte abyReserved[6];
};

the interface functions are something of the form


HRESULT Connect(byte byAddress, byte byOption, short nRet, resp_struct * pResp);
ASKER CERTIFIED SOLUTION
Avatar of BeyondWu
BeyondWu
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You should declare your interface as a raw interface derived from IUnknown, and also create and register the proxy/stub dll.
Sorry, your component is a dll, so you needn't proxy/stub.
You can also use raw interface or dual interface, Actually, you can directly wite HRESULT Connect(byte byAddress, byte byOption, short nRet, RESP_STRUCT
* pResp); because all the variables in the same process context.
// method 'Connect' not emitted because of invalid return type or parameter type


I get this when I try to import my TLB file using class wizard....
I also get this when I try to compile my DLL


warning MIDL2039 : interface does not conform to [oleautomation] attribute : [ Parameter 'pResp' of Procedure 'Connect' ( Interface 'Iwish' ) ]
Ok well I got it work using the #import in VC++

However now I cannot pass my pResp in vb --

Can someone give me some sample code in vb on how to pass the struct into the com interface.
I not very familiar with VB, you can try this:

Dim test As resp_struct
Dim testobj As IYourConnect

Set testobj = New IYourConnect

'the following Initialize the test struct
test.abyReserved(0) = 30
test.abyReserved(1) = 31
test.abyReserved(2) = 32
test.abyReserved(3) = 33
test.abyReserved(4) = 34
test.abyReserved(5) = 35
test.byCommand = 36
test.byError = 37

'Invoke the method
testobj.Connect 30, 31, 32, test

Remark:
You should first select the "Project|Reference" menu in VB,
Then in the "Available References" list select your component, then click "OK" button.

Good Luck
why doesn't the following work then??

testobj.connect (30, 31, 32, test)


I get the following error

---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

Expected: =
---------------------------
OK   Help  
---------------------------
do I need to use out, retval for one of my parameters in my idl file???


1. you can't use this
testobj.connect (30, 31, 32, test)
because it is not a function, has no return value.


2. Which parameter you wanted to return?

For example:
If your function is:
HRESULT getvalue([in]int input, [out, retval]int* retval);
then in VB you can use this:
x = testobj.getvalue(30)
Thanks so much for your help -- It is greatly appreciated