Click here to Skip to main content
11,707,470 members (74,499 online)
Rate this: bad
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 2:46am
Edited 18-Mar-13 3:06am
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
Please Sign up or sign in to vote.

Solution 1

You can cast a CString object to a const pointer Smile | :)
  // 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
0 OriginalGriff 156
1 Sergey Alexandrovich Kryukov 145
2 Mika Wendelius 140
3 chainerlt 110
4 ppolymorphe 104
0 OriginalGriff 9,178
1 Sergey Alexandrovich Kryukov 8,562
2 CPallini 5,189
3 Maciej Los 4,806
4 Mika Wendelius 3,706

Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 18 Mar 2013
Copyright © CodeProject, 1999-2015
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