The MASM Forum Archive 2004 to 2012
Welcome, Guest. Please login or register.
March 23, 2023, 07:23:26 AM

Login with username, password and session length
Search:     Advanced search
128553 Posts in 15254 Topics by 684 Members
Latest Member: mottt
* Home Help Search Login Register
+  The MASM Forum Archive 2004 to 2012
|-+  Project Support Forums
| |-+  MASM32
| | |-+  Calling my dll like rundll32 does causes a MSVCRT abnormal program termination
« previous next »
Pages: [1] Print
Author Topic: Calling my dll like rundll32 does causes a MSVCRT abnormal program termination  (Read 3304 times)
pke
Guest


Email
Calling my dll like rundll32 does causes a MSVCRT abnormal program termination
« on: March 18, 2011, 07:49:00 PM »

I want to call the ANSI method "Popup" defined like a standard rundll32 callable entry proc.

Code:
extern "C" void CALLBACK Popup(HWND, HINSTANCE, LPSTR commandLine, int) {
}

The code below loads the dll successfully and can call the proc. However something in the proc does something with the MSVCRT and this generates the "Abnormal Program Termination" message box.

Quote
---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Runtime Error!

Program: ...\Test.exe



This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.


---------------------------
OK   
---------------------------
Is there something I have to call inside my asm code to initialize the msvcrt? I have checked the WINE port rundll32.c file and could not see any unusual going on there in regards to MSVCRT initialization.

Code:
.386
.model flat, stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\shlwapi.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\shlwapi.lib



.data
dllName db "test",0
funcName db "Popup",0
moduleName db 256 dup (0)

.data?
instance HINSTANCE ?
commandLine LPSTR ?
popupFunc dd ?

.code
start:

invoke GetModuleFileNameA, NULL, addr moduleName, 256
invoke PathStripPathA, addr moduleName
;invoke MessageBoxA,NULL, addr moduleName, NULL, MB_OK
invoke lstrlenA, addr moduleName
mov ebx,eax

invoke GetCommandLineA
add ebx, eax
mov commandLine, ebx
;invoke MessageBoxA,NULL, commandLine, NULL, MB_OK

invoke LoadLibrary, addr dllName
.if eax != NULL
  mov instance,eax
  invoke GetProcAddress, instance, addr funcName
  .if eax  != NULL
    mov popupFunc, eax
    push SW_SHOWDEFAULT
    push commandLine
    push instance
    push 0 ; hwnd   
    call [popupFunc] ; Crashes in msvcrt
  .endif
.else
  ;invoke MessageBox,NULL,addr dllName, NULL, MB_ICONERROR
.endif

invoke ExitProcess,0

end start


Any ideas?
Logged
Vortex
Raider of the lost code
Member
*****
Gender: Male
Posts: 3460



Re: Calling my dll like rundll32 does causes a MSVCRT abnormal program termination
« Reply #1 on: March 18, 2011, 08:08:30 PM »

It's difficult to comment your case without seeing the DLL and the source code. Does your DLL import function(s) from msvcrt.dll ?
Logged

Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP The MASM Forum Archive 2004 to 2012 | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!