Solved

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

Posted on 2001-08-22
20
195 Views
Last Modified: 2013-11-20
How can I pass structures over a com interface... I am looking for a good example....
0
Comment
Question by:Dak_Programmer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 6
  • 3
20 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6415109
0
 

Author Comment

by:Dak_Programmer
ID: 6415387
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++.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6415425
>>Yeah that works fine for vb

Err, scroll down - the article uses VC++...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Dak_Programmer
ID: 6415446
what is pInterface in their code?
0
 
LVL 86

Expert Comment

by:jkr
ID: 6415493
>>what is pInterface in their code?

The pointer to the COM interface.
0
 

Author Comment

by:Dak_Programmer
ID: 6415563
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
0
 

Author Comment

by:Dak_Programmer
ID: 6415640
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
0
 
LVL 9

Expert Comment

by:BeyondWu
ID: 6416126
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.
0
 

Author Comment

by:Dak_Programmer
ID: 6417817
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);
0
 
LVL 9

Accepted Solution

by:
BeyondWu earned 200 total points
ID: 6420506
Try:
typedef     struct resp_struct
     {
       byte byCommand;
       byte byError;
       byte abyReserved[6];
     }RESP_STRUCT, * LPRESP_STRUCT;

HRESULT Connect(byte byAddress, byte byOption, short nRet, [in, out, size_is(sizeof(RESP_STRUCT))]RESP_STRUCT * pResp);
0
 
LVL 9

Expert Comment

by:BeyondWu
ID: 6420517
You should declare your interface as a raw interface derived from IUnknown, and also create and register the proxy/stub dll.
0
 
LVL 9

Expert Comment

by:BeyondWu
ID: 6420584
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.
0
 

Author Comment

by:Dak_Programmer
ID: 6421740
// 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....
0
 

Author Comment

by:Dak_Programmer
ID: 6421747
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' ) ]
0
 

Author Comment

by:Dak_Programmer
ID: 6422781
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.
0
 
LVL 9

Expert Comment

by:BeyondWu
ID: 6427534
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
0
 

Author Comment

by:Dak_Programmer
ID: 6428765
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  
---------------------------
0
 

Author Comment

by:Dak_Programmer
ID: 6428797
do I need to use out, retval for one of my parameters in my idl file???


0
 
LVL 9

Expert Comment

by:BeyondWu
ID: 6430573
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)
0
 

Author Comment

by:Dak_Programmer
ID: 6432313
Thanks so much for your help -- It is greatly appreciated
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Replacement selected text 2 65
Excel Use VBA to get user's Mac Address for their computer 5 331
EvenOdd challenge 10 145
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 1,282
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question