jaberwacky Posted June 9, 2010 Share Posted June 9, 2010 (edited) Hi, I'm new to using and making DLLs and so far I made an example DLL and I have filled it with three functions. The functions return an int, float, and char respectively. I can DLLCall the int and float functions but not the char! I'm not sure what's going on. String doesn't seem to work for me either. My search through the forum didn't have any examples which used char. I included the DLL code too just in case. Any thing you throw my way will be surely appreciated. Global $hDll = DllOpen("D:\CodeBlocks\C++ Programs\Line Alg DLL\bin\Debug\Line Alg DLL.dll") Global $return = DllCall($hDll, "int:cdecl", "Add", "int", 6, "int", 4) ; <-- works ConsoleWrite("@error: " & @error & " Returns: " & $return[0] & @CRLF) Global $return1 = DllCall($hDll, "float:cdecl", "AddF", "float", 5.5, "float", 4.5) ; <-- works ConsoleWrite("@error: " & @error & " Returns: " & $return1[0] & @CRLF) Global $return2 = DllCall($hDll, "char:cdecl", "sendChar", "char", 'A') ; <-- doesn't work ConsoleWrite("@error: " & @error & " Returns: " & $return2[0] & @CRLF) DllClose($hDll) expandcollapse popup#ifndef __MAIN_H__ #define __MAIN_H__ #include <windows.h> /* To use this exported function of dll, include this header * in your project. */ #ifdef BUILD_DLL #define DLL_EXPORT __declspec(dllexport) #else #define DLL_EXPORT __declspec(dllimport) #endif #ifdef __cplusplus extern "C" { #endif void DLL_EXPORT SomeFunction(const LPCSTR sometext); #ifdef __cplusplus } #endif #endif // __MAIN_H__ extern "C" __declspec(dllexport) int Add(int a, int b ) { return a + b; } extern "C" __declspec(dllexport) float AddF(float a , float b ) { return a + b; } extern "C" __declspec(dllexport) char sendChar(char letter) { return letter; } Edited June 9, 2010 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 9, 2010 Share Posted June 9, 2010 (edited) Try Asc('A') since char is technically a number. Edited June 9, 2010 by Richard Robertson Link to comment Share on other sites More sharing options...
Malkey Posted June 9, 2010 Share Posted June 9, 2010 ... ... Global $return2 = DllCall($hDll, "char:cdecl", "sendChar", "char", 'A') ; <-- doesn't work ... Is "char" a valid data type parameter for DllCall(). I was thinking "str", but I could be wrong. Link to comment Share on other sites More sharing options...
ProgAndy Posted June 9, 2010 Share Posted June 9, 2010 (edited) what is the return of @error? If @error = 2 you should try byte instead of char and use Asc('A') Edited June 9, 2010 by ProgAndy *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 Link to comment Share on other sites More sharing options...
Ascend4nt Posted June 9, 2010 Share Posted June 9, 2010 (edited) Yeah, 'char' isn't supported by DLLCall unfortunately. The call would need 'byte' or 'ubyte' and then a simple conversion using BinaryToString(). *edit: Oops, a Chr() conversion would be better Edited June 9, 2010 by Ascend4nt My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs |Â Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) |Â Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
ProgAndy Posted June 9, 2010 Share Posted June 9, 2010 @Ascend4nt: Using ubyte is not a good idea. byte is already an unsigned type, so ubyte is unnecessary and can be removed at any time. I think, it already is. Yes, for this purpose, the functions Asc and Chr are the best. When you have wchar, you should use "WORD" or "ushort" and AscW/ChrW *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 Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 9, 2010 Share Posted June 9, 2010 I didn't realize char isn't supported. My bad. Link to comment Share on other sites More sharing options...
jaberwacky Posted June 10, 2010 Author Share Posted June 10, 2010 (edited) Hai guyz, thanks for the replies! Yes! It took me a minute to figure out what yall meant. Thank you. Global $hDll = DllOpen("D:\CodeBlocks\C++ Programs\Line Alg DLL\bin\Debug\Line Alg DLL.dll") Global $return = DllCall($hDll, "int:cdecl", "AddInt", "int", 6, "int", 4) ; <-- works Report($return[0]) Global $return1 = DllCall($hDll, "float:cdecl", "AddFloat", "float", 5.5, "float", 4.5) ; <-- works Report($return1[0]) Global $return2 = DllCall($hDll, "str:cdecl", "sendString", "str", "hello") ; <-- works Report($return2[0]) Global $return3 = DllCall($hDll, "byte:cdecl", "sendChar", "byte", Asc('A')) ; <-- works Report(Chr($return3[0])) DllClose($hDll) Func Report($report) Return ConsoleWrite("Return: " & $report & @CRLF) EndFunc ;==>Report expandcollapse popup"main.h" //************************************************* #ifndef __MAIN_H__ #define __MAIN_H__ #include <windows.h> /* To use this exported function of dll, include this header * in your project. */ #ifdef BUILD_DLL #define DLL_EXPORT __declspec(dllexport) #else #define DLL_EXPORT __declspec(dllimport) #endif #ifdef __cplusplus extern "C" { #endif void DLL_EXPORT SomeFunction(const LPCSTR sometext); #ifdef __cplusplus } #endif #endif // __MAIN_H__ //************************************************* #include "main.h" #include <Windows.h> using namespace std; extern "C" __declspec(dllexport) int AddInt(int a, int b) { return a + b; } extern "C" __declspec(dllexport) float AddFloat(float a , float b) { return a + b; } extern "C" __declspec(dllexport) LPSTR sendString(LPSTR uhhhhh_like_Words_and_Stuff) { return uhhhhh_like_Words_and_Stuff; } extern "C" __declspec(dllexport) char sendChar(char uhhhhh_like_Words_and_Stuff) { return uhhhhh_like_Words_and_Stuff; } Edited June 10, 2010 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now