This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gnuwince - problem using LoadLibraryW / GetProcAddrW


Hi there,

I'm having difficulities to Load a wince driver dll using LoadLibraryW and then execute a function from the dll located with GetProcAddr.

So far I'm using arm-wince-pe-gcc because I can't compile using g++, but I definitly need g++ so what am I doing wrong, which header am I missing: 

arm-wince-pe-g++ -c -march=armv4 -mapcs-32 -malignment-traps -DNEWLIB -DSARM -DWIN32 -DGNUWINCE -DALIGN64 -DLITENDIAN -O0 -DDEBUG -Dpthreads main.cpp
main.cpp: In function `int CANInit()':
main.cpp:34: error: `MultiByteToWideChar' undeclared (first use this function)

Can't find any header including MultiByteToWideChar but when using gcc there is no problem, isn't that strange? I need to use MultiByteToWideChar to convert the strings to wide char neede by LoadLibraryW and GetProcAddressW.

When compiling with arm-wince-pe-gcc I get a working exe. So far it works well. I can load the dll correctly I think, and I can get the addresses of the functions as well.
But when executing the functions I only get a return value of 0 (no error) when using double* as type for the funtion pointer.

void* is not accepted in gcc but would be required in g++ because when trying to compile with g++ (despite the error mentioned above) i get:
main.cpp:53: error: invalid conversion from `VOID*' to `double (*)()'

the even bigger problem is that I get an access violation (in the coredll module) when executing the second dll function (reset_chip).

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wcebase.h>
#include "/inc/mydll.h"

int HWInit()
{
		HMODULE mylib;
		char *c_str=(char*)malloc(50);
		LPWSTR *uc_str=(LPWSTR*)malloc(500);
		double (*mycall)();
		int ret;

		int ressources;		

		strcpy(c_str,"mydll.dll\0");
		MultiByteToWideChar(0, 0, c_str, 12, uc_str, 500);
		mylib=LoadLibraryW((LPWSTR)uc_str);
		if(my==0) return 1;
		
		strcpy(c_str,"initialize_board\0");
		MultiByteToWideChar(0, 0, c_str, 23, uc_str, 500);
		mycall=GetProcAddressW(libcan, (LPWSTR)uc_str);
		if(mycall==0) return 2;
		
		ressources=0;
		ret=(*mycall)(&ressources);
		if(ret!=0) return ret;

		strcpy(c_str,"reset_board\0");
		MultiByteToWideChar(0, 0, c_str, 18, uc_str, 500);
		mycall=GetProcAddressW(libcan, (LPWSTR)uc_str);
		if(can_call==0) return 3;

		ret=(*mycall)();
		if(ret!=0) return 103;
		
		FreeLibrary(mylib);
		return 0;
}

int main()
{
	int ret;
	FILE *fp;

	fp = fopen("mylog.log", "wb");
	fprintf(fp,"starting...\n\r");

	ret=HWInit();
	if(ret)fprintf(fp,"Error Initializing Board, Error %i\n\r",ret);
	else fprintf(fp,"Hardware initialized...\n\r");

	fclose(fp);
	return 0;
}

the makfile entry looks like this as requested by Craig, the man behind the gnuwince project (hope thats right!?!)

wince:	main.cpp
	arm-wince-pe-g++ -c -march=armv4 -mapcs-32 -malignment-traps -DNEWLIB -DSARM -DWIN32 -DGNUWINCE -DALIGN64 -DLITENDIAN -O0 -DDEBUG -Dpthreads main.cpp
	arm-wince-pe-g++ -o main_wince.exe -s main.o -lstdc++ -lsupc++ -lm -lc -lgcc -lwinsock -lcoredll

My questions:
- how to make this compile with arm-wince-pe-g++ (don't understand the point why it finds MultiByteToWideCharW using gcc but not when using g++)
- any suggestions why I get an access violation in the coredll module when executing the second dll funtion, what kind of type do funtion pointers have to be (in c as well as in c++)?
note: the dll definiately works when using evc compiler. target platform is a compaq ipaq 3950.

Any help that might get me closer to solve those problems is highly appreciated.
thanks a lot, Tobi


------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]