Link to home
Start Free TrialLog in
Avatar of RandomLogic
RandomLogic

asked on

Using non-Unicode compiled dll with a unicode program

We have a dll compiled in unicode having for example a follwing function header:

void foo(TCHAR* pChar);

the side using the dll 'sees' this as an unsigned short while in actuality it was compiled in the dll as a char. As a result the linker throws an 'unresolved external' cuz it can't find the implementation it's looking for.

We tried hacking this by doing something like the follwing

#ifdef _UNICODE
#undef _UNICODE
void foo(TCHAR* pChar);
#define _UNICODE

so that the app side will think it's a char too, but apperently the TCHAR is evaluated before this (Precompiled headers??) so it still thinks it's an unsigned short. What can we do about this?

Just so I'm clear, we want to be able to send a char* to foo().

cheers,
RL
Avatar of jkr
jkr
Flag of Germany image

>>we want to be able to send a char* to foo().

Then, you'll need to use a wrapper for that function, e.g.

void fooA(char* pChar) {

wchar_t* pwsz = new wchar_t [strlen(pChar) + 1];

wsprintfW ( pwsz, L"%S", psz);

foo(pwsz); // call with UNICODE string

delete [] pwsz;
}
ASKER CERTIFIED SOLUTION
Avatar of wayside
wayside

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial