2 Replies - 3103 Views - Last Post: 26 October 2009 - 03:17 PM Rate Topic: -----

#1 DangerD  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 01-September 09

Converting C++ String to LPCH

Post icon  Posted 26 October 2009 - 01:49 PM

I'm trying to avoid char arrays in my program and use C++ strings but I'm having a problem with a conversion.

string FilePath;
GetModuleFileName(NULL, FilePath, FilePath.length());



error C2664: 'GetModuleFileNameA' : cannot convert parameter 2 from 'std::string' to 'LPCH'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

I've tried quite a few things with no luck...

LPCH is defined as
typedef CHAR *LPSTR, *LPCH;

Thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: Converting C++ String to LPCH

#2 DangerD  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 01-September 09

Re: Converting C++ String to LPCH

Posted 26 October 2009 - 02:15 PM

I guess I just need to do it like this?
	char buf[MAX_PATH];
	GetModuleFileName(NULL, buf, sizeof(buf));
	string FilePath = buf;


Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6081
  • View blog
  • Posts: 23,556
  • Joined: 23-August 08

Re: Converting C++ String to LPCH

Posted 26 October 2009 - 03:17 PM

Yes, that works (you probably know that now).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1