Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2001-08-22
20
Medium Priority
?
213 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 800 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

971 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