Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Ahk and C++


  • Please log in to reply
2 replies to this topic
chubaka845
  • Members
  • 2 posts
  • Last active: Apr 13 2013 02:33 PM
  • Joined: 12 Apr 2013

Hi I have got a problem with making a Dll which exports functions that can be used in (Unicode) ahk scripts.

If I compile my ahk script to ansi it works but my script should support Unicode characters..

 

C++ code in msvc++ 2010 (default settings)

#ifdef _UNICODE
#ifndef UNICODE
#define UNICODE
#endif
#endif

#include <windows.h>


 
// DLL entry function (called on load, unload, ...)
BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
{
    return TRUE;
}
 
// Exported function - adds two numbers
extern "C" __declspec(dllexport) int AddNumbers(int a, int b)
{
    return a + b;
}

ahk_l code

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%


hModule := DllCall("LoadLibrary", Str, A_ScriptDir . "\DLL_1.dll")
if(hModule == -1 || hModule == 0)
{
	MsgBox, 48, Fehler, Fehler
	ExitApp
}

AddNumbers_func := DllCall("GetProcAddress", UInt, hModule, Str, "AddNumbers")


AddNumbers(a, b)
{
	global AddNumbers_func
	Result := DllCall(AddNumbers_func, Int, a, Int, b)
	return Result
}


Msgbox % AddNumbers(100,200)
exitapp


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
GetProcAddress requires an 8-bit string. Use AStr instead of Str.

chubaka845
  • Members
  • 2 posts
  • Last active: Apr 13 2013 02:33 PM
  • Joined: 12 Apr 2013

thanks