Game Development Community

Copying strings in C

by Neil Marshall · in Torque Game Engine · 03/01/2006 (7:03 am) · 1 replies

I've got what is probably a really simple error which I can't figure out.

I'm working on a plugin version of Torque and am in the process of rewriting the entry code into the engine. So before the main function is called I need to grab some information from the windows registry.


static char mainCSPathA[512];
   DWORD size = sizeof( mainCSPathA );
   if ( RegQueryValueEx( regKey, L"main.cs", NULL, NULL, (unsigned char *) mainCSPathA, &size ) != ERROR_SUCCESS ) 
   {
      // ...
   }

Then I need to compile this into the "command line" so I'm doing this:

LPCSTR commandLine[2];
   commandLine[1] = mainCSPathA;

Now when I call S32 ret = Game->main(2,commandLine); all I recieve on the other end is the first chatacter of the path. So I get "c" instead of "c:\projects\tge\example\main.cs". I can see that it's only grabbing the first byte, but I don't know how to grab the entire string instead.

I know the code on the other end is working because if I pass:
LPCSTR commandLine[2];
   commandLine[1] = "c:\projects\tge\example\main.cs";
instead, then it works.

#1
03/01/2006 (1:54 pm)
I figured out the problem. Because TGE 1.4 is compiled with unicode RegQueryValueEx returns a wide character where the second byte is null, so when I tried to display the string it hit ["c", null, ":", null....] and it stopped at the first null.

The simple fix was calling RegQueryValueExA directly.