本文介绍了在WIN32中获取Application Stratup路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好..

正在像这样检索应用程序Stratup路径:

Hello ..

Am retriving the application Stratup path like this:

char buffer2[2048];
char buffer1[5120];
GetModuleFileName(NULL, buffer2, 5120);



在buffer2中,输出为:
c:\ Users \ guruprasad \ Desktop \ gscanner \ Debug \ gscanner.exe

而且,实际上,我想截断gscanner.exe,这样我的最终输出应该是:
c:\ Users \ guruprasad \ Desktop \ gscanner \ Debug \

请给我建议.


在此先感谢..!



In buffer2 am getting output as:
c:\Users\guruprasad\Desktop\gscanner\Debug\gscanner.exe

And,Actually i want to truncate gscanner.exe, so that my final output should be:
c:\Users\guruprasad\Desktop\gscanner\Debug\

Please suggest me..


Thanks in Advance..!

推荐答案

#include <windows.h>
#include <stdio.h>
#include <tchar.h>

#define BUFSIZE MAX_PATH

void _tmain()
{
   TCHAR Buffer[BUFSIZE];
   DWORD dwRet;

   dwRet = GetCurrentDirectory(BUFSIZE, Buffer);
   _tprintf(TEXT("Current directory: %s\n"), Buffer);

}



std::string ExtractDirectory( const std::string& path )
  {
  return path.substr( 0, path.find_last_of( '\\' ) +1 );
  }

int main()
{
char buffer2[2048];
char buffer1[5120];


GetModuleFileName(NULL, buffer2, 2048);

std::string dir = ExtractDirectory(std::string(buffer2));

}


这篇关于在WIN32中获取Application Stratup路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 03:39