For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > April 2007 > Writing a DLL that can be used in Perl with Win32::API









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Writing a DLL that can be used in Perl with Win32::API
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

Scrume2

2007-04-24, 6:08 pm

Halle Berry in anal action!
http://Halle-Berry-anal-action.org/...hp?movie=148803
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com