[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.axapta.programming

Microsoft Visual C++ DLL

TonnieH

12/12/2005 9:21:00 PM

I build a DLL with Microsoft Visual C++ 2005, tested it from a C-program and
it works ok. When I call it from within Axapta, I keep getting the message
'DLL Function not found'. I think it has something to do with the way the
function names are exported in the DLL (which convention). Does anyone has a
sample how to do this in C++?
2 Answers

onno

12/14/2005 10:37:00 AM

0

Hi,

you have to create a Module-Definition-File (*.def) for the exported
function and you have to declare that function with WINAPI (__stdcall) .

Example:


****************************
* DemoDll.h (for use in other C/C++ projects)
****************************
#include <windows.h>
int WINAPI DemoStrLen(char *Str);


****************************
* DemoDll.cpp
****************************
#include <string.h>
#include "DemoDll.h"

int WINAPI DemoStrLen(char *Str)
{
return strlen(Str);
}


****************************
* DemoDll.def
****************************
LIBRARY "DemoDll"
EXPORTS
DemoStrLen @1


****************************
* Axapta Job for testing the Dll
****************************
static void DemoDll(Args _args)
{
DLL DLL = new DLL("C:\\Dokumente und Einstellungen\\torsten\\Eigene
Dateien\\Visual Studio 2005\\Projects\\DemoDll\\DemoDll\\Debug\\DemoDll.dll");
DLLFunction DemoStrLen = new DLLFunction(DLL, "DemoStrLen");

DemoStrLen.arg(ExtTypes::String);
DemoStrLen.returns(ExtTypes::DWord);
print DemoStrLen.call("Hallo");
pause;
}

This should work. Additionally you can check the exported symbols with
dependency viewer. Your function should be listed with the name you defined
in your sources.

Regards,
Onno

TonnieH

12/19/2005 9:06:00 AM

0

Hi. This defenitly put me in the right direction. After some tests I made the
following changes :
- declare the functions as 'extern "C" __declspec( dllexport )'
- and set the calling convention to _stdcall instead of _cdecl

Now it works fine. Thx,

Tonnie

"onno" wrote:

> Hi,
>
> you have to create a Module-Definition-File (*.def) for the exported
> function and you have to declare that function with WINAPI (__stdcall) .
>
> Example:
>
>
> ****************************
> * DemoDll.h (for use in other C/C++ projects)
> ****************************
> #include <windows.h>
> int WINAPI DemoStrLen(char *Str);
>
>
> ****************************
> * DemoDll.cpp
> ****************************
> #include <string.h>
> #include "DemoDll.h"
>
> int WINAPI DemoStrLen(char *Str)
> {
> return strlen(Str);
> }
>
>
> ****************************
> * DemoDll.def
> ****************************
> LIBRARY "DemoDll"
> EXPORTS
> DemoStrLen @1
>
>
> ****************************
> * Axapta Job for testing the Dll
> ****************************
> static void DemoDll(Args _args)
> {
> DLL DLL = new DLL("C:\\Dokumente und Einstellungen\\torsten\\Eigene
> Dateien\\Visual Studio 2005\\Projects\\DemoDll\\DemoDll\\Debug\\DemoDll.dll");
> DLLFunction DemoStrLen = new DLLFunction(DLL, "DemoStrLen");
>
> DemoStrLen.arg(ExtTypes::String);
> DemoStrLen.returns(ExtTypes::DWord);
> print DemoStrLen.call("Hallo");
> pause;
> }
>
> This should work. Additionally you can check the exported symbols with
> dependency viewer. Your function should be listed with the name you defined
> in your sources.
>
> Regards,
> Onno