|
-
December 25th, 2009, 12:25 PM
#1
compile c++ dll for visual basic
HI, I have a previous c++ file that has all the code I need for my current project. Normally I would just rewrite it for visual basic but it requires tons of work arounds to complete. (The code involves nodes and pointers and tons of different stuff that visual basic doesn't fully support.) I understand there is a way to compile c++ code into a dll file though and call it in visual basic. I know you have to create a header file and a def file or something but I have no idea how about going about this. Any tutorials or sample code would be much appreciated.
Thank You
-
December 25th, 2009, 06:38 PM
#2
Re: compile c++ dll for visual basic
You don't need a def file, you should be able to import the functions directly as long as you use __stdcall. I work with a guy who uses VB and I've written quite a few libraries for him. It doesn't even need to be Visual C++, I do it in MinGW.
-
December 28th, 2009, 05:13 AM
#3
Re: compile c++ dll for visual basic
Just export the required functions as __stdcall (or WINAPI) and you can very well use that C++ DLL in VB.
Regards,
Ramkrishna Pawar
-
December 29th, 2009, 03:11 AM
#4
Re: compile c++ dll for visual basic
and you can very well use that C++ DLL in VB
Well, it will be so until it comes to exchanging strings, arrays, collections and other VB-specific stuff, when it immediately becomes a headache.
Best regards,
Igor
-
December 29th, 2009, 03:13 AM
#5
Re: compile c++ dll for visual basic
I understand there is a way to compile c++ code into a dll file though and call it in visual basic.
Sure. The way is called ActiveX.
Best regards,
Igor
-
December 30th, 2009, 06:45 AM
#6
Re: compile c++ dll for visual basic
moddll.cpp:
Code:
#define ABSTR BSTR
char pText2[] = "0123456789 123456789 123456789 123456789";
extern "C" __declspec(dllexport) ABSTR __stdcall PassString(LPSTR pText)
{
int pTextLen = SysStringByteLen((ABSTR)pText);
strncpy(pText, pText2, pTextLen);
return SysAllocStringByteLen(pText2, strlen(pText2));
}
ABSTR __stdcall PassStringByDEFFile(LPSTR pText)
{
int pTextLen = SysStringByteLen((ABSTR)pText);
strncpy(pText, pText2, pTextLen);
return SysAllocStringByteLen(pText2, strlen(pText2));
}
__declspec(dllexport) ABSTR __stdcall PassStringByCPP(LPSTR pText)
{
int pTextLen = SysStringByteLen((ABSTR)pText);
strncpy(pText, pText2, pTextLen);
return SysAllocStringByteLen(pText2, strlen(pText2));
}
BOOL APIENTRY DllMain( HANDLE hModule, ...
moddll.def:
Code:
; moddll.def : Declares the module parameters.
LIBRARY "moddll.DLL"
EXPORTS
DllMain @1 PRIVATE
PassStringByDEFFile
basmoddll.bas:
Code:
Private Declare Function PassString Lib ".\moddll.dll" Alias "_PassString@4" (ByVal s As String) As String
Private Declare Function PassStringByDEFFile Lib ".\moddll.dll" (ByVal s As String) As String
Private Declare Function PassStringByCPP Lib ".\moddll.dll" Alias "?PassStringByCPP@@YGPAGPAD@Z" (ByVal s As String) As String
Sub Main()
Dim s As String, s1 As String
s = "xxxxx"
s1 = PassString(s)
s = "xxx"
s1 = PassStringByDEFFile(s)
s = "ZZZZZZZ"
s1 = PassStringByCPP(s)
End Sub
With best wishes,
Vita
-----------------------
Russian Software Development Network -- http://www.rsdn.ru
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|