0

Using

LPTSTR  strDLLPath1 = new TCHAR[_MAX_PATH];
::GetModuleFileName((HINSTANCE)&__ImageBase, strDLLPath1, _MAX_PATH);

I get path to my DLL which it correctly prints.

D:\Test\work\EasyDLL\Debug\EasyDLL.dll

Now I just need the "D:\Test\work\EasyDLL\Debug\".

Given my experience using VC++ can you guide me in best way to do that - any string replace, conversion etc.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
Amit Pandey
  • 1,436
  • 2
  • 24
  • 34
  • 3
    See the [`_splitpath`](http://msdn.microsoft.com/en-us/library/e737s6tf%28v=vs.100%29.aspx) function, or the [Boost filesystem](http://www.boost.org/doc/libs/1_52_0/libs/filesystem/doc/index.htm) [`path`](http://www.boost.org/doc/libs/1_52_0/libs/filesystem/doc/reference.html#class-path) class. – Some programmer dude Nov 23 '12 at 12:29
  • 1
    Or _splitpath_s, as _splitpath is deprecated... – Liam Nov 23 '12 at 13:10
  • Example using `std::string` member functions: http://stackoverflow.com/questions/8518743/get-directory-from-file-path-c/8518793#8518793 – hmjd Nov 23 '12 at 14:07

1 Answers1

3

Look at shell patch handling functions, and more precisely at PathRemoveFileSpec, which does exactly what you want.

You will need to link with shlwapi.lib.

Étienne
  • 407
  • 4
  • 15
  • that really solved my problem as of now. any issues seen as of now in terms of compatibility across windows platforms by any one? – Amit Pandey Nov 23 '12 at 14:08