| vessep@gmail.com 2007-04-23, 6:58 pm |
| Hello all,
I'm having trouble in writing a DLL that I could invoke from Perl
using Win32::API (ActivePerl 5.8.7.813)
I've been trying to write a simple DLL with Visual Studio .NET 2003.
I've created a new project: Visual C++ Projects -> Win32 -> Win32
Console Project. I've set the application type to DLL and checked the
Export symbols -checkbox. After modifying the provided code I've got
what I've listed at the end of the code. I compiled this with default
settings and a DLL appeared.
When running the Perl code, Win32.:API->Import -call fails (Perl code
at the end also). DLL is in the same directory and compiled ok.
dumpbin /exports shows the function to have name _fnFooDll@0, which
obviously does not match with what I've given in import call. I
haven't found out that how should I make the DLL so that function
exports would look like what I've defined in the code, or how to call
a function like that from Perl. I only found this http://tinyurl.com/yvo3sl
(link points to a thread in groups.google.com), but it did not help...
Any advice or link would be highly appreciated. I've (hopefully) set
the follow-up to comp.os.ms-windows.programmer.win32 since I'd believe
that this is not a Perl issue as such.
BR,
vesse
Perl -code:
****************************************
*******************
#!perl -w
use strict;
use Win32::API;
Win32::API->Import('FooDll', 'int fnFooDll()') or die("Error: $! \n");
fnFooDll();
C++ -code:
****************************************
*******************
FooDll.h:
#ifdef FOODLL_EXPORTS
#define FOODLL_API __declspec(dllexport)
#else
#define FOODLL_API __declspec(dllimport)
#endif
extern "C" FOODLL_API int __stdcall fnFooDll();
FooDll.cpp:
#include "stdafx.h"
#include "FooDll.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
FOODLL_API int __stdcall fnFooDll()
{
return 42;
}
dumpbin output:
****************************************
*******************
Dump of file FooDll.dll
File Type: DLL
Section contains the following exports for FooDll.dll
00000000 characteristics
462CBE94 time date stamp Mon Apr 23 17:11:32 2007
0.00 version
1 ordinal base
1 number of functions
1 number of names
ordinal hint RVA name
1 0 000114BF _fnFooDll@0
Summary
4000 .data
1000 .idata
5000 .rdata
2000 .reloc
1F000 .text
10000 .textbss
|