problem when use dll.so from wine app

Open forum for end-user questions about Wine. Before asking questions, check out the Wiki as a first step.
Forum Rules
Locked
david.nguyen
Newbie
Newbie
Posts: 2
Joined: Sun Dec 14, 2008 10:25 pm

problem when use dll.so from wine app

Post by david.nguyen »

Hi all,

i write a windows dll and use it on linux system following:

1. i use windump to dump dll to .spec, .c, .h file
winedump spec Simple.dll -f Simple -I "*.h"
it export 3 file: Simple.spec, Simple_main.c, Simple_dll.h

2. i use wingcc to build stub dll(native dll)
winegcc Simple_main.c Simple.spec -o libSimple -shared -fPIC
it export file : libSimple.dll.so

3. i write wine app and link to libSimple.dll.so: main.c

#include "Simple_dll.h"

int main(int argc, char **argv) {
SIMPLE_ShowText();
return 0;
}

i use winegcc to complie main.c and link to lib:
winegcc main.c -o main -L. -lSimple.dll
it complie and link ok but when i run app then it error is:
err:seh:setup_exception_record stack overflow 828 bytes in thread 0009 eip 60063d4f esp 00230ff4 stack 0x230000-0x231000-0x330000

anybody know why pls help me, my process correct or not?

Thanks very much,
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: problem when use dll.so from wine app

Post by vitamin »

david.nguyen wrote:i use winegcc to complie main.c and link to lib:
winegcc main.c -o main -L. -lSimple.dll
Not correct. See this topic: http://forum.winehq.org/viewtopic.php?t=3177

Also double check calling conventions. Keep in mind default is cedecl not stdcall aka WINAPI.
david.nguyen
Newbie
Newbie
Posts: 2
Joined: Sun Dec 14, 2008 10:25 pm

Post by david.nguyen »

Thank you very much,

I had try the same way that you say but still not work and still the same error

Following is my windows dll

1. Simple.h:

Code: Select all

__declspec(dllexport) void ShowText()
2. Simple.c

Code: Select all

#include "Simple.h"
#include <stdio.h>
void ShowText()
{
	printf("Hello world\n");
}
i build and generate Simple.dll

3. install wine and copy Simple.dll to my folder on linux system

4. use winedump to general .spec, .c, .h
winedump spec Simple.dll -f Simple -I "*.h"
=>Simple.spec, Simple_main.c, Simple_dll.h

- Simple.spec content:

Code: Select all

# Generated from Simple.dll by winedump

1 cdecl ?ShowText@@YAXXZ() SIMPLE_global_ShowText_1
#import Simple.dll
- Simple_dll.h content:

Code: Select all

/*
 * Simple.dll
 *
 * Generated from Simple.dll by winedump.
 *
 * DO NOT SEND GENERATED DLLS FOR INCLUSION INTO WINE !
 * 
 */
#ifndef __WINE_SIMPLE_DLL_H
#define __WINE_SIMPLE_DLL_H

#include "windef.h"
#include "wine/debug.h"
#include "winbase.h"
#include "winnt.h"


void __cdecl SIMPLE_global_ShowText_1(void);



#endif	/* __WINE_SIMPLE_DLL_H */
- Simple_main.c content:

Code: Select all

/*
 * Simple.dll
 *
 * Generated from Simple.dll by winedump.
 *
 * DO NOT SUBMIT GENERATED DLLS FOR INCLUSION INTO WINE!
 *
 */

//#include "config.h"

#define __WINESRC__

#include <stdarg.h>

#include "windef.h"
#include "winbase.h"
#include "Simple_dll.h"
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(Simple);


HMODULE hDLL=0;	/* DLL to call */

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
	TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);

	switch (fdwReason)
	{
		case DLL_WINE_PREATTACH:
			return FALSE;    /* prefer native version */
		case DLL_PROCESS_ATTACH:
			hDLL = LoadLibraryA("Simple");
			TRACE("Forwarding DLL (Simple) loaded (%p)\n", hDLL);
			break;
		case DLL_PROCESS_DETACH:
			FreeLibrary(hDLL);
			TRACE("Forwarding DLL (Simple) freed\n");
			break;
		default:
			break;
	}

	return TRUE;
}


/******************************************************************
 *		?ShowText@@YAXXZ (SIMPLE.1)
 *
 *
 */
void __cdecl SIMPLE_global_ShowText_1(void)
{
	void (__cdecl *pFunc)(void);
	pFunc=(void*)GetProcAddress(hDLL,"?ShowText@@YAXXZ");
	TRACE("(void): forward\n");
	pFunc();
	TRACE("Returned (void)\n");
}
5. use winegcc to build libSimple.dll.so
winegcc Simple_main.c Simple.spec -o libSimple -shared -fPIC
=> libSimple.dll.so

6. write test program main.c:

Code: Select all

#include "Simple_dll.h"

int main(int argc, char **argv) {
	SIMPLE_global_ShowText_1();
   	return 0;
} 
7. use winegcc to build it by command line such as you say but still not work:
winegcc -Bwinebuild -I/usr/include/wine -I/usr/lib/wine -mwindows main.c -o main -lSimple.dll -luser32 -lkernel32
My process is correct?

Thank you very much
Locked