You don't need to save EBX, it's done by the compiler for you. But I don't see why you need to use EBX in the first place - nor why you really need to use inline assembler (that will ensure that your code won't be portable to Windows x64 if you should wish to do that later on.
Some simplification in red:
Code:
void a(char *string, HWND rsHwnd)
{
sMessage = (DWORD)GetProcAddress(LoadLibrary("User32.dll"), "SendMessageA");
LPARAM lstring = LPARAM(string);
__asm {
mov eax, rsHwnd
cmp eax, 0
je $invalidHandle
push lstring
push 0
push VM_SETTEXT
push eax
call sMessage
$invalidHandle:
};
}
Alternative C-code:
Code:
typedef LRESULT (*tpSendMessage)(
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
void a(char *string, HWND rsHwnd)
{
static tpSendMessage pSendMessage = 0;
if (rsHwnd) {
if (!pSendMessage) {
pSendMessage = GetProcAddress(LoadLibrary("User32.dll"), "SendMessageA");
if (!pSendMessage) { ... do some error handling ... }
}
pSendMessage(rsHwnd, VM_SETTEXT, 0, LPARAM(string));
}
}
Note, I made pSendMessage a static variable, so once it's been "found", you don't need to call GetProcAddress/LoadLibrary again.
--
Mats