Solved

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

Posted on 2001-08-22
20
187 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now