?
Solved

Problem related to CString usage.

Posted on 2013-01-21
3
Medium Priority
?
524 Views
Last Modified: 2013-01-21
This should be easy, but I can't figure it out.  I'm trying to call a function from MFC based C++ code.  The function signature is:
Add(HZIP hz, const TCHAR *dstzn, void *src, unsigned int len, DWORD flags);

The 3rd parameter is what is causing my problem.  It is supposed to be the full path and file name of a file to be taken into a process.  In my case that full path is contained in a CString object.  I've tried several ways to get the CStrinng content into an acceptable format, but I cannot get anything to work.  For example, if I use the CString directly, I get the compiler complaint:
C2664: Add: cannot convert parameter 3 from 'CString' to 'void *'

if I try (LPCSTR)CString I get:
C2664: 'Add' : cannot convert parameter 3 from 'LPCSTR' to 'void *'      

Using VS2005

Any help would be appreciated.  Thanks
0
Comment
Question by:Onager
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Expert Comment

by:virtuadept
ID: 38801271
Cast you CString as (void *). The third parameter is expecting a void pointer.

More specifically, lets say you have a variable "path" which is a Cstring,

parm3 should be:

... , (void *) &path, ...


& means the address of, so that is casting address of "path" as void pointer.
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 600 total points
ID: 38802083
I think it is not correct to cast CString directly to void *
Regarding LPCTSTR, it returns a const pointer, which cannot be casted automatically to non-const void pointer
I would use CString::GetBuffer() instead (http://msdn.microsoft.com/en-us/library/aa314880(v=vs.60).aspx), which returns a LPTSTR, which is non-const
0
 

Author Closing Comment

by:Onager
ID: 38802379
Both solutions got me past the compiler complaint but the 1st solution failed inside of the called function.  The getbuffer approach worked like a charm.

Thanks to both.  Mike
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question