// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"

#include "stdafx.h"
#include "dllmain.h"

//因为内存DLL没有名字不能使用GetModuleHandle获取当前DLL句柄，应在DLL入口中纪录hModule句柄到全局变量_dll_hModule中
HMODULE _dll_hModule;

BOOL APIENTRY DllMain( HMODULE 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:
		_dll_hModule = hModule; 
		break;
	}
	return TRUE;
}

//用于获取AAuto函数
void * (* aau_getfunction )(const char* funcName,const char* funcProto) ;
//用于增加AAuto函数
bool (* aau_setfunction )(const char* funcName,void * pfunc,const char* funcProto) ;

STDCALL_DLL_API  void __stdcall ExportAAuto( void * (*getfunction_cdecl)(const char*,const char*),bool (*setfunction_cdecl)(const char*,void* pfunc,const char*)   ) {
	aau_getfunction = getfunction_cdecl;  
	aau_setfunction = setfunction_cdecl;

	//使用 aau_getfunction 直接导入AAuto函数
	typedef void * (* aau_docode)(const char*) ;
	aau_docode func = (aau_docode)aau_getfunction("raw.export.docode","string(string code");
	func("io.print('Welcome to AAuto.');");
}

STDCALL_DLL_API int __stdcall AAutoApiTest(int a, int b) 
{
	//HRSRC hrSrc = FindResource(_dll_hModule ,"test.aau", "LIB");
	//HGLOBAL hGlobal = LoadResource(_dll_hModule, hrSrc);
	//LPVOID lpsz = LockResource(hGlobal);
	//UINT len = (UINT)SizeofResource(_dll_hModule, hrSrc);

	//MessageBox(NULL,(char *)lpsz,0,0);
	////
	//FreeResource(hGlobal); 

	return a + b;
}


