Click here to Skip to main content
12,997,441 members (59,812 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I design one Win32 Dll application, in which one function returns handle and parameter is String so I used LPSTR in Dll application 'c' file,it builds successfully but when I using that function is MFC dialogue based application and I passed CString argument to that function,but it gives error as
Error  C2664: ': cannot convert parameter 1 from 'CString' to 'LPWSTR'  

so what are the arguments pass to that function?
Posted 18-Mar-13 2:46am
Updated 18-Mar-13 3:06am
ThePhantomUpvoter 18-Mar-13 9:14am
Well if I were you, I would be passing a LPWSTR as a parameter. Did you try casting your CString to the correct type?
Tadit Dash 18-Mar-13 9:43am
[Reply from OP]

No! how to cast that?
Richard MacCutchan 18-Mar-13 9:50am
Have you set the project's character set to UNICODE?
Jochen Arndt 18-Mar-13 9:59am
You should show us the relevant code parts. Passing CString objects to/from DLLs is problematic. If the string is constant (not changed by the function that receives it) and processed immediately (function did not use the string after the CString object goes out of scope), it may be sufficient to define the parameter as LPCTSTR.

A CString can not be casted to LPWSTR / LPSTR / LPTSTR. These types are not const (string can be changed). To access a CString to change the content, use CString::GetBuffer() and CString::ReleaseBuffer() when finished.
nv3 18-Mar-13 10:32am
Thank would get my 5 if you posted it as a solution.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can cast a CString object to a const pointer :)
  // use szEntry here
  return hRet;
// CString CYourDlg::m_cszEntry
void CYourDlg::OnTest()
  HANDLE hEntry(Test(m_cszEntry));
  // use hEntry here

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 18 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100