Jump to content

Recommended Posts

Posted

I have written a simple c++ dll, using Visual C++ Studio 2008 Express Edition. The test.cpp file is as follows:

// Dll Function definition   
__declspec(dllexport) int __stdcall myFunction(void) {    
    return 7;   
}

__declspec(dllexport) int __stdcall mySum(int x , int y) {
    return x + y;
}

I created the file using the File Menu --> New --> Project, Click Win32 --> Win32 Project (calling it test)

Then clicked Application Settings --> DLL and Empty Project

The project complies without any problems.

I then try to use that dll in Auto-it with the following code:

Dim $theReturnValue
$theReturnValue=DllCall("C:\Documents and Settings\User\My Documents\Visual Studio 2008\Projects\test\Debug\test.dll", "int", "myFunction")

However @error is set to 3 ("function" not found in the DLL file) and there is no return value.

I have been working on this for many hours, I'm sure I have over looked some very simple, can somebody please help me.

Thanks

Posted

C++ makes strange names. It adds some Chars and numvers at the beginning of the Function name.

So you have to declare them with extern "C" :)

http://www.codeguru.com/forum/showthread.php?t=231254

// Dll Function definition  
extern "C" __declspec(dllexport) int __stdcall myFunction(void) {     
    return 7;  
}

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Posted

My c++ dll now reads

// Dll Function definition   
extern "C" __declspec(dllexport) int __stdcall myFunction (void) {    
    return 7;   
}

extern "C" __declspec(dllexport) int __stdcall mySum (int x , int y) {
    return x + y;
}

However the @error is still set to 3, I even tried changing to a .c file instead of a .cpp file.

Hmmm :) I still can't seem to work out what is wrong.

I dont have dumpbin to check the exported function names, how else can you do it?

Thanks Again

Posted

Open the Dll with dependency walker and lookup the Names.

I thjink, there is something added at the end, too @x where x is the ordianl number. Read the posted link to remove this :)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Posted

Try compile it without __stdcall.

Just remember that you need add :cdecl in the DllCall function after the return type.

Broken link? PM me and I'll send you the file!

Posted

Thanks Heaps..

I used LipDump (http://www.freedownloadscenter.com/Programming/Misc__Programming_Tools/LibDump_Download.html)

to get a list of the exported function names.

I found myFunction was called _myFunction@0 so using

$theReturnValue=DllCall("C:\Documents and Settings\User\My Documents\Visual Studio 2008\Projects\test\Debug\test.dll","int", "_myFunction@0")
msgbox(0,"",$theReturnValue[0])

Worked!!! :)

Thanks again... I'll keep playing....

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...