Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Problem related to CString usage.

Posted on 2013-01-21
3
Medium Priority
?
553 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 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
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…
Loops Section Overview

810 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