如何使用Visual C ++在Windows Mobile中获取应用程序路径

时间:2009-08-15 09:14:28

标签: visual-c++ windows-mobile

我有一个应用程序从“images \”文件夹加载相对于应用程序所在位置的少量图像文件。任何人都可以告诉我如何在Visual C ++中获取该位置。快速谷歌搜索显示,没有简单的方法。有人可以帮我解决这个问题吗?

由于 DM

1 个答案:

答案 0 :(得分:2)

使用GetModuleFilename()获取应用程序的完整路径并删除可执行文件名称:

    wchar_t appPath[ MAX_PATH ];
    memset( appPath, 0, MAX_PATH * sizeof( wchar_t ) );

    wchar_t modulePath[MAX_PATH];
    if ( GetModuleFileName( NULL, modulePath, MAX_PATH ) > 0 )
    {
        wchar_t *lastBackSlash = wcsrchr( modulePath, '\\' );
        if ( lastBackSlash )
        {
            memcpy( appPath, modulePath, ( lastBackSlash - modulePath ) * sizeof( wchar_t ) );
        }
    }