Please help - Calling a VC++ Dll from VB 
Author Message
 Please help - Calling a VC++ Dll from VB

I have looked all over for a solution to no avail. Maybe one of you can
help.

I have a VC++ DLL with the function defined like this:
COMMON_EXPORT void MyFunc (CString FileName, CString InputStr, CString
*OutputStr);

I have declared the function in my VB program like this:

Private Declare Sub MyFunc Lib "Common" Alias "#2" _  'use ordinal number
(ByVal ProjPath As String, ByVal ProjVar As String, ByRef StorString As
Variant)

And the call is:
MyFunc ProjectName + vbNullChar, "top_assembly:" + vbNullChar, TopAsslyName

But, it does not work. The host exe within which both these DLLs run crashes
when the line executes.

Any ideas?

- Sam



Sun, 03 Apr 2005 22:46:17 GMT  
 Please help - Calling a VC++ Dll from VB

Quote:
"SAm" wrote...
> I have looked all over for a solution to no avail. Maybe one of you
can
> help.

> I have a VC++ DLL with the function defined like this:
> COMMON_EXPORT void MyFunc (CString FileName, CString InputStr, CString
> *OutputStr);

> I have declared the function in my VB program like this:

> Private Declare Sub MyFunc Lib "Common" Alias "#2" _  'use ordinal
number
> (ByVal ProjPath As String, ByVal ProjVar As String, ByRef StorString
As
> Variant)

> And the call is:
> MyFunc ProjectName + vbNullChar, "top_assembly:" + vbNullChar,
TopAsslyName

> But, it does not work. The host exe within which both these DLLs run
crashes
> when the line executes.

Is this a function you wrote?  Because as shown it will never work with
VB.

1) VB doesn't understand CString, use lpstr instead.  And you don't need
to append null characters.

2) The last parameter should be ByRef As String, not As Variant.  If
you're intending to return a value in that string, you must pass in a
string with enough length to hold the largest possible result.

3) Does COMMON_EXPORT somehow #define to __stdcall?  VB can only call
__stdcall functions.

4) If you use a DEF file in the C project, you don't need to alias the
function name to an ordinal.

--

    Jim Mack
    MicroDexterity Inc
    www.microdexterity.com



Mon, 04 Apr 2005 10:41:54 GMT  
 Please help - Calling a VC++ Dll from VB


Quote:
>4) If you use a DEF file in the C project, you don't need to alias the
>function name to an ordinal.

It's C++, so the names will be mangled.
He will either have to stick to ordinals or use extern "C" on the
declarations.

--
Regards, Frank



Mon, 04 Apr 2005 10:50:58 GMT  
 Please help - Calling a VC++ Dll from VB

Quote:
"Frank Adam" wrote...

> >4) If you use a DEF file in the C project, you don't need to alias
the
> >function name to an ordinal.

> It's C++, so the names will be mangled.
> He will either have to stick to ordinals or use extern "C" on the
> declarations.

> --
> Regards, Frank

We don't know what COMMON_EXPORT includes, it may well have extern "C".
The header file will show for sure.  My broader point was that the
functions must be __stdcall, and those names aren't mangled, just
lightly decorated :-)

--

    Jim Mack
    MicroDexterity Inc
    www.microdexterity.com



Mon, 04 Apr 2005 19:04:11 GMT  
 Please help - Calling a VC++ Dll from VB
Thanks for the tips, guys. Will try them out and let you know how it goes.

- Sam


Quote:
> "Frank Adam" wrote...

> > >4) If you use a DEF file in the C project, you don't need to alias
> the
> > >function name to an ordinal.

> > It's C++, so the names will be mangled.
> > He will either have to stick to ordinals or use extern "C" on the
> > declarations.

> > --
> > Regards, Frank

> We don't know what COMMON_EXPORT includes, it may well have extern "C".
> The header file will show for sure.  My broader point was that the
> functions must be __stdcall, and those names aren't mangled, just
> lightly decorated :-)

> --

>     Jim Mack
>     MicroDexterity Inc
>     www.microdexterity.com



Mon, 04 Apr 2005 23:41:32 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Calling VC++ programs and VC created dlls from VB

2. HELP! Calling a VC DLL from VB

3. HELP! Calling a VC DLL from VB

4. Converting VB codes to VC++ DLL ......... please help

5. Need help passing a DC handle from vb to a vc++ dll

6. How to create DLL for subtractio in vc++ and how to call in it in

7. Please Help MAPILogon call in VC++ 6

8. problem with calling DLL(VC++) from VB application

9. Problem in Calling VC++ DLL in VB code on WinCE

10. calling vb dll from VC++

11. calling VC++ DLL from VB

12. Problem in call to VC++ dll from VB

 

 
Powered by phpBB® Forum Software