Valhalla Legends Archive

Programming => General Programming => Topic started by: UserLoser. on June 26, 2004, 06:26 PM

Title: [C++/VB] Bad calling convention, making no sense [fixed & still makes no sense]
Post by: UserLoser. on June 26, 2004, 06:26 PM
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:


BOOL WINAPI InitWinsock()
{
  WSADATA lpWSAData;
  return WSAStartup(0x0202, &lpWSAData);
}


In exports.def:

EXPORTS

@1=InitWinsock


So basically, now at ordinal #1, is my InitWinsock function.  In VB, here's how I'm declaring it:


Public Declare Function InitWinsock Lib "ElBotCore.dll" Alias "#1" () As Long


I've tried using it in two different ways, and both ways do not seem to work.

Doing...:

Call InitWinsock


Causes a runtime error (Bad DLL calling convention)

And also I tried:


   Dim lngInitWinsock As Long
   lngInitWinsock = InitWinsock()


Which gives another error and the program crashes:


---------------------------
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  
---------------------------


Any help appreciated.



Somehow I fixed this, all I did was rewrite my exports.def file, and rewrote some of the other functions, still makes no sense..
Title: Re:[C++/VB] Bad calling convention, making no sense [fixed & still makes no sens
Post by: Sargera on June 27, 2004, 07:29 PM
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...


#include <stdio.h>
int main(void) {
   int x;
   printf("%s", x); // memory cannot be read error
   return 0;
}
Title: Re:[C++/VB] Bad calling convention, making no sense [fixed & still makes no sens
Post by: Adron on June 30, 2004, 05:31 PM
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.
Title: Re:[C++/VB] Bad calling convention, making no sense [fixed & still makes no sens
Post by: TheMinistered on July 07, 2004, 11:32 AM
Make sure WINAPI is defined as __stdcall, could be a broken header file?!