Advertisement

Conversion from CHAR to WCHAR

Started by November 11, 2000 10:41 AM
5 comments, last by dennis428 24 years, 1 month ago
Hi folks, I''m trying to initialize a DirectMusic object, but I need to pass the executable''s directory as a WCHAR to the Loader->SetSearchDirectory function. In a tutorial I saw the MultiByteToWideChar function that convertes CHAR to WCHAR, but when I use it, it only copies one character to the destination buffer. Does anyone know why this happens? The macro for the function is:

#define MULTI_TO_WIDE( x,y )  MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, y, -1, x, _MAX_PATH );

funtion()
{
    char szDir[_MAX_PATH];
    WCHAR wszDir[_MAX_PATH];

    if(_getcwd( szDir, _MAX_PATH ) == NULL)
    {
        return NULL;
    }

    // at this point szDir = "D:\cpp\Direct3D tutorial 1"

    // convert szDir to wszDir
    MULTI_TO_WIDE(wszDir, szDir);

    // wszDir = "D"
}
I hope you folks can help me so I won''t have to make a ''dead'' game. If there is a better function than _getcwd to get the directory where the program executable resides (preferably as a WCHAR), I sure would like to hear about it too. Dennis
visit my site, please:members.nbci.com/dennis428/default.htm
instead of query for the .exe directory

you can use ".\" and it will default to the "working directory" enter in the short-cut (9/10 its the .exe path too, and you can change the short-cut if its not)
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement
Thanks for the advice, but I really need the conversion. Maybe someone else can help me?
There must be someone who knows the MultiByteToWideChar() function.

Dennis
visit my site, please:members.nbci.com/dennis428/default.htm
TEXT("exe path"); should do. Just #define UNICODE before it then #undef it after.

Of course, you can always declare the executables directory as a wchar_t variable.

-----------------------------

A wise man once said "A person with half a clue is more dangerous than a person with or without one."

The Micro$haft BSOD T-Shirt
-----------------------------A wise man once said "A person with half a clue is more dangerous than a person with or without one."The Micro$haft BSOD T-Shirt
  //-----------------------------------------------------------------------------// Name: DXUtil_ConvertAnsiStringToWide()// Desc: This is a UNICODE conversion utility to convert a CHAR string into a//       WCHAR string. cchDestChar defaults -1 which means it //       assumes strDest is large enough to store strSource//-----------------------------------------------------------------------------VOID DXUtil_ConvertAnsiStringToWide( WCHAR* wstrDestination, const CHAR* strSource,                                      int cchDestChar ){    if( wstrDestination==NULL || strSource==NULL )        return;    if( cchDestChar == -1 )        cchDestChar = strlen(strSource)+1;    MultiByteToWideChar( CP_ACP, 0, strSource, -1,                          wstrDestination, cchDestChar-1 );    wstrDestination[cchDestChar-1] = 0;}   


this what you wanted?

Edited by - magmai kai holmlor on November 12, 2000 9:19:46 PM
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
There are DirectX utility functions to convert to/from Unicode now.

Look at the DX8 DirectPlay SimpleServer sample and search for something like "wszSessionName". It''ll be there.
Advertisement
Thanks for all the help folks. I better get some work done, real fast.

Dennis


visit my site, please:
members.nbci.com/dennis428/default.htm
visit my site, please:members.nbci.com/dennis428/default.htm

This topic is closed to new replies.

Advertisement