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
Solved

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

Posted on 2001-08-22
20
194 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ BOOL WINAPI ReadFile fails on windows 10 when reading from USB cable 9 468
deburging in oracle form 12 104
iSeries DB2 Query 2 97
mapBully challenge 6 152
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 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