PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Cannot compile this code under VC++ .NET

In my ongoing problems with using VC++ .NET to compile my project, I found this function which I cannot get to compile:

Code:

bool TRender::DrawText(const TCHAR *Text, LONG X, LONG Y, TRenderContext Context, TSurface *Surface, LONG OffsetX, LONG OffsetY)
{
// defs
LONG DX,DY,DrawX=0,DrawY=0;

// get surface position
DrawX = X - Context.RenderPort.left;
DrawY = Y - Context.RenderPort.top;

// Set the X,Y position on the destination surface
DX = (DrawX*Display->TileWidth)+OffsetX;
DY = (DrawY*Display->TileHeight)+OffsetY;

// paint this tile on the surface
if(Surface->DrawText(DX,DY,Text,RGB(255,255,255),GDDRAWTEXT_BORDER,NULL,NULL)) return false;

// all went well
return true;
}


TSurface is a CGapiSurface to which I added SetBrightness() and SetContrast().

Under eVC++ everything compiled without a single warning.

I'm linking with gapidraw/lib/xp/gd104.lib. I tried to remove this lib to see if it was indeed linkink, and then I got dozens and dozens of errors. Leaving it in place just generates a few.

I tried to place the gd104.lib in the same directory as the project, and I even re-downloaded GapiDraw1.04 to make sure I had the correct files.

Finally, I checked to make sure I had no other GapiDraw.h, or gd104.lib lying around.

I just can't make it work. On the other hand, every single samples of GapiDraw works flawlessly. I tried to include my own files in one of the sample's project, but still no cigar.

Here are the errors generated:

Code:

Minimal error LNK2019: unresolved external symbol "__declspec(dllimport) public: long __thiscall CGapiBitmapFont::CreateFontW(unsigned long,struct _GDFONTFX *)" (__imp_?CreateFontW@CGapiBitmapFont@@QAEJKPAU_GDFONTFX@@@Z) referenced in function "public: void __thiscall TFonts::LoadFonts(void)" (?LoadFonts@TFonts@@QAEXXZ)
Minimal error LNK2019: unresolved external symbol "__declspec(dllimport) public: long __thiscall CGapiSurface::CreateSurface(wchar_t const *)" (__imp_?CreateSurface@CGapiSurface@@QAEJPB_W@Z) referenced in function "public: void __thiscall TFonts::LoadFonts(void)" (?LoadFonts@TFonts@@QAEXXZ)
Minimal error LNK2001: unresolved external symbol "__declspec(dllimport) public: long __thiscall CGapiSurface::CreateSurface(wchar_t const *)" (__imp_?CreateSurface@CGapiSurface@@QAEJPB_W@Z)
Minimal error LNK2019: unresolved external symbol "__declspec(dllimport) public: long __thiscall CGapiSurface::SaveSurface(wchar_t const *)" (__imp_?SaveSurface@CGapiSurface@@QAEJPB_W@Z) referenced in function "public: bool __thiscall TGame::SaveScreenShot(wchar_t const *)" (?SaveScreenShot@TGame@@QAE_NPB_W@Z)
Minimal error LNK2019: unresolved external symbol "__declspec(dllimport) public: long __thiscall CGapiSurface::DrawTextW(unsigned long,unsigned long,wchar_t const *,unsigned long,unsigned long,struct _GDTEXTFX *,unsigned long *)" (__imp_?DrawTextW@CGapiSurface@@QAEJKKPB_WKKPAU_GDTEXTFX@@PAK@Z) referenced in function "public: bool __thiscall TRender::DrawTextW(wchar_t const *,long,long,struct TRenderContext,class TSurface *,long,long)" (?DrawTextW@TRender@@QAE_NPB_WJJUTRenderContext@@PAVTSurface@@JJ@Z)
Minimal error LNK2019: unresolved external symbol "__declspec(dllimport) public: long __thiscall CGapiSurface::DrawTextW(unsigned long,unsigned long,wchar_t const *,class CGapiBitmapFont *,unsigned long,struct _GDTEXTFX *,unsigned long *)" (__imp_?DrawTextW@CGapiSurface@@QAEJKKPB_WPAVCGapiBitmapFont@@KPAU_GDTEXTFX@@PAK@Z) referenced in function "public: bool __thiscall TRender::CreateTextBoxOverlay(long,long,char const *)" (?CreateTextBoxOverlay@TRender@@QAE_NJJPBD@Z)
Minimal error LNK2019: unresolved external symbol _WinMain@16 referenced in function _WinMainCRTStartup
Minimal fatal error LNK1120: 6 unresolved externals


I don't know where the one on line #7 comes from, I just started to see this one.

Can anyone help? Anyone came across this problem with VC++ .NET?

Thanks...

:cry: :cry:
Ok, I have found part of the problem, but not the solution.

In VC++ .NET, you can set your project to use UNICODE or MULTIBYTE.

Under multibyte, all my wcscpy() and such would generate errors, because it cannot convert "TCHAR *" to "wchar_t *". (DUH... Aren't they the same?)

So, if you set your program to UNICODE, it works, but the linker chokes with the errors I gave in the previous post.

So, leaving the project under Multibyte seems to be the only solution I found, but then DrawText() and other GapiDraw function calls expect a TCHAR, and wcscpy() expect wchar_t.

I'm stumped. Is there a trick I can use to make some type of conversion?

Thanks.
The trick is really quite simple, always use Unicode. I can't think of any real reason to use Multibyte.
Or.. you can always use TCHARs

instead of wcscpy(), use:

_tcscpy()

instead of sprintf, use:

_stprintf()

and so on.. a TCHAR will automatically be 8-bit multibyte on stationary platforms and 16-bit unicode on WinCE...
That works too. (Shouldn't answer programming threads a 3 AM). Actually though, if your stationary target is predominantly NT based systems (NT 4, 2k, XP) then there's a performance boost for using Unicode on these systems as well because all the API is unicode based and the multi-byte functions have to convert the strings to unicode internally.

Anyways, you should always use TCHARs and the TCHAR functions regardless.
When I started programming for the PPC, I found TCHARs to be annoying, so I sticked to CHARs for anything not related to APIs...

Now I pay the price, in having to convert lots of code! :cry:

Thanks for all your inputs.

--Eric