Author | Message | Time |
---|---|---|
UserLoser. | [s]I'm writing a DLL in C++ to manage most of the features on something new of mine, which the main application is written in VB. I'm not sure why this isn't working, so that's why I'm posting it. Code from DLL: [code] BOOL WINAPI InitWinsock() { WSADATA lpWSAData; return WSAStartup(0x0202, &lpWSAData); } [/code] In exports.def: [code] EXPORTS @1=InitWinsock [/code] So basically, now at ordinal #1, is my InitWinsock function. In VB, here's how I'm declaring it: [code] Public Declare Function InitWinsock Lib "ElBotCore.dll" Alias "#1" () As Long [/code] I've tried using it in two different ways, and both ways do not seem to work. Doing...: [code] Call InitWinsock [/code] Causes a runtime error (Bad DLL calling convention) And also I tried: [code] Dim lngInitWinsock As Long lngInitWinsock = InitWinsock() [/code] Which gives another error and the program crashes: [pre] --------------------------- vb6.exe - Application Error --------------------------- The instruction at "0x02b0121e" referenced memory at "0x00000000". The memory could not be "read". Click on OK to terminate the program Click on CANCEL to debug the program --------------------------- OK Cancel --------------------------- [/pre] Any help appreciated. [hr] Somehow I fixed this, all I did was rewrite my exports.def file, and rewrote some of the other functions, still makes no sense.. | June 26, 2004, 11:26 PM |
Sargera | Usually a memory read error is the result of trying to use data in a manner that is unacceptable by the function or whatever you're using it with...For instance, in C... [code] #include <stdio.h> int main(void) { int x; printf("%s", x); // memory cannot be read error return 0; }[/code] | June 28, 2004, 12:29 AM |
Adron | A bad calling convention error is typically the result of trying to call a cdecl or fastcall function from VB. It can also happen if you don't pass the right number of arguments. | June 30, 2004, 10:31 PM |
TheMinistered | Make sure WINAPI is defined as __stdcall, could be a broken header file?! | July 7, 2004, 4:32 PM |