Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newb: C++ Program accessed by VB

Status
Not open for further replies.

CasperTFG

Programmer
Nov 15, 2001
1,210
US
I have a DLL, that I can only interface with, using C++. Problem is the majority of the program is already written in VB, and I know very little of the C/C++ language.

I need some help in creating an EXE or DLL in C++ that VB can make calls to. Speed is important but not that important, so if it is easier to make and EXE rather than a DLL with less than 50% impact on speed then that is fine.

Here is an example of the Code given for C. Now what I need to know is how do I pass in a buffer of data and recieve back a buffer of data from this function.

[tt]
#include <windows.h>
#include <iostream>

using namespace std;

typedef int (*init)();
typedef void (*exec)(char *sendbuffer, char *recvbuffer);

int main(int argc, char *argv[])
{
char buffer[2048];

// Load MyCDLL.DLL
HINSTANCE hDll = LoadLibrary(&quot;MyCDLL.dll&quot;);

// Setup a pointer to the 'initializeDefaults' function in MyCDLL.DLL
init initializeDefaults = (init)GetProcAddress(hDll,&quot;initializeDefaults&quot;);

// Setup a pointer to the 'execute' function in MyCDLL.DLL
exec execute = (exec)GetProcAddress(hDll,&quot;execute&quot;);

// Initialize the Defaults in MyCDLL.DLL - Should Only Be Called Once
initializeDefaults();

// Send an MyCDLL command to the DLL
execute(&quot;[AOECHO;AGTEST;]&quot;, buffer);
// Display the result of the command
cout << buffer << endl;

execute(&quot;[AOECHO;AGTEST;]&quot;, buffer);
cout << buffer << endl;
execute(&quot;[AOECHO;AGTEST;]&quot;, buffer);
cout << buffer << endl;


return 0;
}
[/tt]

Thanks, Craig, mailto:sander@cogeco.ca

Remember not to name the Lambs...
It only makes the chops harder to swallow
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top