In Visual Studio 200x, it is a little difficult to directly convert cstring to const char *. The following is a feasible solution:
// Obtain the directory path
Cstring mpath = DLG. getpathname ();
// Convert the directory path to an absolute path for cvloadimage to call
Int M = mpath. getlength ();
For (INT Index = 0; index <m; index ++)
{
If (mpath. getat (INDEX) = '\\')
{
Mpath. insert (index ,'\\');
Index ++;
}
}
// Convert the cstring to the lpctstr
Lpctstr P = mpath. getbuffer ();
/*
Convert the lpctstr to const char *. Due to Unicode problems1. Const char * in a non-Unicode Environment *2. In the Unicode environment
Const unsigned short *
In Case 2, you need to use the API FunctionWidechartomultibyte
Int widechartomultibyte (uint codePage, // code page DWORD dwflags, // performance and mapping flags lpcwstr lpwidecharstr, // wide-character string int cchwidechar, // Number of chars in string lpstr lpmultibytestr, // buffer for new string int cbmultibyte, // size of buffer lpcstr lpdefaultchar, // default for unmappable chars lpbool lpuseddefachar char // set when default char used );
*/
DWORD dwminsize;
Dwminsize = widechartomultibyte (cp_acp, null, P,-1, null, 0, null, false );
Char * PP = new char [dwminsize];
Widechartomultibyte (cp_oemcp, null, P,-1, PP, dwminsize, null, false );
// Read the image
Iplimage * IP1 = cvloadimage (PP,-1 );