Click here to Skip to main content
15,913,115 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
VB
Error  C2664: ': cannot convert parameter 1 from 'CString' to 'LPWSTR'  

so what are the arguments pass to that function?
Posted
Updated 18-Mar-13 3:06am
v2
Comments
[no name] 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?
[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

You can cast a CString object to a const pointer :)
C++
HANDLE Test(LPCTSTR szEntry)
{
  HANDLE hRet(NULL);

  // use szEntry here

  return hRet;
}

// CString CYourDlg::m_cszEntry
void CYourDlg::OnTest()
{
  UpdateData(TRUE);
  
  HANDLE hEntry(Test(m_cszEntry));
  
  // use hEntry here
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900