How pass struc as argument from C++ to VB 
Author Message
 How pass struc as argument from C++ to VB

Hi all,

From MSDN I have downloaded Q200150 HOWTO: Call a Visual Basic ActiveX DLL
to
Send Mail. To me this looks like a very neat example of how to call a
function in a visual basic DLL

I would like to modify this to  call from C++ a Visual Basic function
that expects two or more user defined functions as parameters ?   How do I
do this.

I realise that variant_t could be used to store the struct to be passed as
argument to my VB function. This leads me to conclude that I have to change
line 17,18 en 22 in the code below to hold my user-defined function.

Could you give me some pointers on how to do this?

Kindest regards

Guno

From Q200150 HOWTO: Call a Visual Basic ActiveX DLL to Send Mail
1.  The following C code (Win 32 Application) is used to create and call the
ActiveX DLL:
2.  // activexdll1.cpp : Defines the entry point for the application.
3.  //
4.  #include "stdafx.h"
5.  #include <objbase.h>
6.  // Change to include your DLL
7.  #import "Project2.dll" no_namespace
8.  int APIENTRY WinMain(HINSTANCE hInstance,
9.                       HINSTANCE hPrevInstance,
10.                      LPSTR     lpCmdLine,
11.                      int       nCmdShow)
12. {
13. // Initialize COM
14.    CoInitialize(NULL);
15.    //  Change to the name of the person
16.    //  you wish to send the message
17.    _variant_t name ("alias");
18.    _variant_t subject ("Testing ActiveX DLL");
19.    // Create an instance of the ActiveX object
20.    // Where Class1 is the class module of your Project2
21.    _Class1Ptr oDLL("Project2.Class1");
22.    oDLL->sendmail(&name.bstrVal,&subject.bstrVal);
23.    oDLL = NULL;
24.    CoUninitialize();
25.    return 0;

Quote:
}



Thu, 15 Jul 2004 05:20:03 GMT  
 How pass struc as argument from C++ to VB
On Sat, 26 Jan 2002 22:20:03 +0100, "Guno van Engel"

Quote:

>Hi all,

>From MSDN I have downloaded Q200150 HOWTO: Call a Visual Basic ActiveX DLL
>to
>Send Mail. To me this looks like a very neat example of how to call a
>function in a visual basic DLL

>I would like to modify this to  call from C++ a Visual Basic function
>that expects two or more user defined functions as parameters ?   How do I
>do this.

>I realise that variant_t could be used to store the struct to be passed as
>argument to my VB function. This leads me to conclude that I have to change
>line 17,18 en 22 in the code below to hold my user-defined function.

Firstly, I'd recomment that you use a COM object rather than a struct
- it would be easier.  Having said that, it *is* possible to pass
structs over the COM interface - see this article:
http://www.mvps.org/vcfaq/com/4.htm
If you're having difficulty, it is because (as the article says) SP4
didn't fix this - you need the SDK.

I don't know how VB would react to this though.

James

--
I do not own any hippos.  But they do sometimes stray into my email
address.
Remove them to email me.



Thu, 15 Jul 2004 07:20:14 GMT  
 How pass struc as argument from C++ to VB
Hi James,

Thanks for your input, I came up with the code below. Would you please
review this and provide me with some feedback.

At the VB side, Prjdll.dll with  the following class clsdll.
The function expect two users defined types by ref as parameters.

I came up with this line to call the function from C++
Could you give me some feedback .

t->fnCallDll (&psMystruc1, &psMystruc1);

Kindest regards
Guno

//

#include "stdafx.h"
#include <objbase.h>

const Mystruc11  *psMystruc1
const Mystruc12  *psMystruc2

// Change to include your DLL

#import "Prjdll.dll" no_namespace

int APIENTRY WinMain(HINSTANCE hInstance,
                      HINSTANCE hPrevInstance,
                      LPSTR     lpCmdLine,
                       int       nCmdShow)
{

// Initialize COM

CoInitialize(NULL);

HRESULT hresult;

CLSID clsid;

CoInitialize(NULL); //initialize COM library

hresult=CLSIDFromProgID(OLESTR("prjdll.clsdll"), &clsid);    //retrieve
CLSID of component

_clsdll *t;

hresult=CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,__uuidof(_clsdll),(
LPVOID *) &t);

if(FAILED(hresult))

{
 AfxMessageBox("Creation Failed");
 return;

Quote:
}

t->fnCallDll (&psMystruc1,& psMystruc1);  //call method

t->Release();   //call method

CoUninitialize();  //Unintialize the COM library

   return 0;

Quote:
}



Quote:
> On Sat, 26 Jan 2002 22:20:03 +0100, "Guno van Engel"

> >Hi all,

> >From MSDN I have downloaded Q200150 HOWTO: Call a Visual Basic ActiveX
DLL
> >to
> >Send Mail. To me this looks like a very neat example of how to call a
> >function in a visual basic DLL

> >I would like to modify this to  call from C++ a Visual Basic function
> >that expects two or more user defined functions as parameters ?   How do
I
> >do this.

> >I realise that variant_t could be used to store the struct to be passed
as
> >argument to my VB function. This leads me to conclude that I have to
change
> >line 17,18 en 22 in the code below to hold my user-defined function.

> Firstly, I'd recomment that you use a COM object rather than a struct
> - it would be easier.  Having said that, it *is* possible to pass
> structs over the COM interface - see this article:
> http://www.mvps.org/vcfaq/com/4.htm
> If you're having difficulty, it is because (as the article says) SP4
> didn't fix this - you need the SDK.

> I don't know how VB would react to this though.

> James

> --
> I do not own any hippos.  But they do sometimes stray into my email
> address.
> Remove them to email me.



Sun, 18 Jul 2004 04:45:36 GMT  
 How pass struc as argument from C++ to VB
Guno,

sure I will take a peek at your code if you like.  But do me a favour
and email me the stuff in a ZIP file - the DLL and the C++ project,
and then I can trace through it line by line rather than looking
directly at code (headache time for something like this).

I will be out tomorrow (job interview), but I can take a look tomorrow
evening (but I *may* be going out so it *could* be Thurs morning).

In the meantime, you may want to have a look at:
http://www.btinternet.com/~james.ingram/code/COMObjectsC.html

Which has some useful links too.

James

--
I do not own any hippos.  But they do sometimes stray into my email
address.
Remove them to email me.

On Tue, 29 Jan 2002 21:45:36 +0100, "Guno van Engel"

Quote:

>Hi James,

>Thanks for your input, I came up with the code below. Would you please
>review this and provide me with some feedback.

>At the VB side, Prjdll.dll with  the following class clsdll.
>The function expect two users defined types by ref as parameters.

>I came up with this line to call the function from C++
>Could you give me some feedback .

>t->fnCallDll (&psMystruc1, &psMystruc1);

>Kindest regards
>Guno

>//

>#include "stdafx.h"
>#include <objbase.h>

>const Mystruc11  *psMystruc1
>const Mystruc12  *psMystruc2

>// Change to include your DLL

>#import "Prjdll.dll" no_namespace

>int APIENTRY WinMain(HINSTANCE hInstance,
>                      HINSTANCE hPrevInstance,
>                      LPSTR     lpCmdLine,
>                       int       nCmdShow)
>{

>// Initialize COM

>CoInitialize(NULL);

>HRESULT hresult;

>CLSID clsid;

>CoInitialize(NULL); //initialize COM library

>hresult=CLSIDFromProgID(OLESTR("prjdll.clsdll"), &clsid);    //retrieve
>CLSID of component

>_clsdll *t;

>hresult=CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,__uuidof(_clsdll),(
>LPVOID *) &t);

>if(FAILED(hresult))

>{
> AfxMessageBox("Creation Failed");
> return;
>}

>t->fnCallDll (&psMystruc1,& psMystruc1);  //call method

>t->Release();   //call method

>CoUninitialize();  //Unintialize the COM library

>   return 0;
>}



>> On Sat, 26 Jan 2002 22:20:03 +0100, "Guno van Engel"

>> >Hi all,

>> >From MSDN I have downloaded Q200150 HOWTO: Call a Visual Basic ActiveX
>DLL
>> >to
>> >Send Mail. To me this looks like a very neat example of how to call a
>> >function in a visual basic DLL

>> >I would like to modify this to  call from C++ a Visual Basic function
>> >that expects two or more user defined functions as parameters ?   How do
>I
>> >do this.

>> >I realise that variant_t could be used to store the struct to be passed
>as
>> >argument to my VB function. This leads me to conclude that I have to
>change
>> >line 17,18 en 22 in the code below to hold my user-defined function.

>> Firstly, I'd recomment that you use a COM object rather than a struct
>> - it would be easier.  Having said that, it *is* possible to pass
>> structs over the COM interface - see this article:
>> http://www.mvps.org/vcfaq/com/4.htm
>> If you're having difficulty, it is because (as the article says) SP4
>> didn't fix this - you need the SDK.

>> I don't know how VB would react to this though.

>> James

>> --
>> I do not own any hippos.  But they do sometimes stray into my email
>> address.
>> Remove them to email me.



Sun, 18 Jul 2004 05:45:24 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. problems with C/C++ DLL passing arguments to VB Callback Function

2. Arguments : Passing Arguments containing <">

3. Arguments pass short 8.3 filename, how pass LFN?

4. Passing Arguments / Passing an Array

5. Passing structs as arguments from VB to C

6. VB Word Hyperlink passing Arguments

7. Passing arguments to a vb .exe file from the command line

8. Passing command line arguments to OCX in VB?

9. passing arguments to executable in VB 6.0

10. passing arguments to vb app when calling it

11. Passing arguments to VB prog?

12. Passing arguments to a VB application

 

 
Powered by phpBB® Forum Software