Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC VC++
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 3:46am
Edited 18-Mar-13 4:06am
v2
Comments
ThePhantomUpvoter at 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 at 18-Mar-13 9:43am
   

[Reply from OP]
 
No! how to cast that?
Richard MacCutchan at 18-Mar-13 9:50am
   
Have you set the project's character set to UNICODE?
Jochen Arndt at 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 at 18-Mar-13 10:32am
   
Thank would get my 5 if you posted it as a solution.

1 solution

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

Solution 1

You can cast a CString object to a const pointer Smile | :)
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
}
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 269
1 OriginalGriff 240
2 CPallini 195
3 Maciej Los 177
4 BillWoodruff 173
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 18 Mar 2013
Copyright © CodeProject, 1999-2014
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