Link to home
Start Free TrialLog in
Avatar of ennixo
ennixoFlag for France

asked on

C++ DLL with Dev-CPP for use in Visual Basic 6

My Dll's export are twined and decorated
ex: For the function void __stdcall HelloWorld(void) i've got : _Z10HelloWorldv@0 and _Z10HelloWorldv

How do i get a export that i can just call HelloWorld without Alias "_Z10HelloWorldv" ?

Here's my Source :

==========================
Def.h
==========================

#include "windows.h"
#define export __declspec (dllexport)

export void __stdcall HelloWorld (void);

==========================
main.cpp
==========================
#include "Def.h"

void __stdcall HelloWorld (void)
{
    MessageBox(NULL,"Hello !","Message",MB_OK);
}
Avatar of vascov
vascov
Flag of United States of America image

extern "C"
{
      export void __stdcall HelloWorld();
}


extern "C"
{
      void __stdcall HelloWorld()
      {
            // something
      }
}



HTH
Avatar of ennixo

ASKER

thanx a lot ! no more decoration !

but my exports are still twins :
HelloWorld
HelloWorld@0

can't i get only HelloWorld alone ?
extern "C"
{
  export void __cdecl HelloWorld();
}

extern "C"
{
  void __cdecl HelloWorld()
  {
    // something
  }
}


Either that, or use the /EXPORT and .def file approach.

HTH
Avatar of ennixo

ASKER

well i tried with __cdecl, it works but then the function cannont be called from VB6...

and i tried with a .def file but i think i don't write the good code because nothing changes :
here is what i tried in testlib.def
LIBRARY testlib
EXPORTS
    HelloWorld    @1


i tried a few things in the .def file but no result...
what should i write ?
If you use __stdcall or __cdecl, VB will know how to find it's way into the correct entrypoint.
Did you get any error when calling from VB6 ? (i tried it with both conventions, and both worked)

On any case, if you really need the entrypoint undecorated:

cl mylib.cpp /EXPORT:HelloWorld

or

cl mylib.cpp /LINK /DEF:mylib.def

where mylib.def is:
LIBRARY mylib
EXPORTS
       HelloWorld      @1


HTH
Avatar of ennixo

ASKER

sorry i thought i said i am a newnewnewbie to C++ and its compilation...

cl mylib.cpp /LINK /DEF:mylib.def
where do i put this ???

__stdcall works perfectly, my vb calls HelloWorld and it works but there are still 2 exports
__cdecl there is only "HelloWorld" export but my VB didn't find the entry point...
Sorry :)

Which version of VC++ are you using ?
Can you also share the Declares you're using in VB6 ?

Assuming VC7.1 (2003), you should:
Menu Project
Properties
Linker
Input
Module Definition File -> set this to the .def file you've just added into your project

Let me know if this works for you.

HTH
Avatar of ennixo

ASKER

i don't have VC++, only Dev-C++ (http://www.bloodsheld.com) :-/

but i found --no-export-all-symbols --add-stdcall-alias in the linker (Project > Properties > Linker)
i tried to add myfile.def, it changed a little the compilation but nothing changed in the dll...
Avatar of Dang123
Dang123

Listening
Hi, i'll have to download the compiler and play with it.

(downloading as we speak)
ASKER CERTIFIED SOLUTION
Avatar of vascov
vascov
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ennixo

ASKER

ok, thanx a lot !!!!
i learned that i must have HelloWorld and HelloWorld@0 because of stdCall
and stdCall is absolutely needed for my functions to be called by VB... (CDecl really doesn't work with VB)

i think you can ear more points from me with this question :
https://www.experts-exchange.com/questions/20806513/Passing-a-dynamic-array-from-VB-to-a-C-DLL-as-parameter.html
Avatar of ennixo

ASKER

* earn, not ear !!
How C DLL's can be created from ordinary .c file and how it can be called from an VB6.0 application.