P/invoking doesnt work

G

Guest

I need to p/invoke this win32 dll: (main parts of it

named: thelib.dl

(compiled with visual c++ 6

#define WINVER 0x50
#include <windows.h
#include <ras.h

#ifdef _cplusplu
#define EXPORT extern "C" _declspec(dllexport
#els
#define EXPORT _declspec (dllexport
#endi


BOOL WINAPI DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserve


return TRUE



EXPORT BOOL CALLBACK thelibfunction(

//stuff (mosty ras functions
return true


i have put the dll directly at c:, for test purposes

the c# propram, in which i invoke (parts of it

using System
using System.Drawing
using System.Collections
using System.ComponentModel
using System.Windows.Forms
using System.Data
using System.Runtime.InteropServices

namespace dllimportin

public class Form1 : System.Windows.Forms.For

[DllImport("c:\\thelib.dll", EntryPoint="thelibfunction", ExactSpelling=true, CharSet=CharSet.Auto)



public static extern bool thelibfunction()

//constructor stuff and els

...

private void Form1_Load(object sender, System.EventArgs e

thelibfunction()


if i run this, i get the failure: The entrypoint 'mylibfunction' was not found in c:\thelib.dl

if i change the DllImport line to this: [DllImport("c:\\thelib.dll")], and touch nothing else, the same failure appears too

Any idea what the failure is? Thanks.
 
G

Guest

This problem is solved, no help needed anymore

If you will encounter something like this

use dumpbin.exe (search your vs.net folder for that), call it

dumpbin thelib.dll /export

That output will come


Dump of file thelib.dl

File Type: DL

Section contains the following exports for thelib.dl

00000000 characteristic
4003A67B time date stamp Tue Jan 13 09:04:11 200
0.00 versio
1 ordinal bas
1 number of function
1 number of name

ordinal hint RVA nam

1 0 00001010 ?thelibfunction@@YAHX

Summar

4000 .dat
1000 .rdat
1000 .relo
 
C

Claes Bergefall

Or use a .DEF file in your C++ project instead of _declspec(dllexport).
It's the _declspec(dllexport) stuff that mangles the name

/claes

no help needed anymore said:
This problem is solved, no help needed anymore.

If you will encounter something like this:

use dumpbin.exe (search your vs.net folder for that), call it:

dumpbin thelib.dll /exports

That output will come:



Dump of file thelib.dll

File Type: DLL

Section contains the following exports for thelib.dll

00000000 characteristics
4003A67B time date stamp Tue Jan 13 09:04:11 2004
0.00 version
1 ordinal base
1 number of functions
1 number of names

ordinal hint RVA name

1 0 00001010 ?thelibfunction@@YAHXZ

Summary

4000 .data
1000 .rdata
1000 .reloc
in EntryPoint (in [DllImport]) and not just thelibfunction.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top