• Welcome to Valhalla Legends Archive.
 

[C++/VB] Bad calling convention, making no sense [fixed & still makes no sense]

Started by UserLoser., June 26, 2004, 06:26 PM

Previous topic - Next topic

UserLoser.

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

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


#include <stdio.h>
int main(void) {
   int x;
   printf("%s", x); // memory cannot be read error
   return 0;
}

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.

TheMinistered

Make sure WINAPI is defined as __stdcall, could be a broken header file?!