Solved

Problem related to CString usage.

Posted on 2013-01-21
3
461 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
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 150 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now