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
Solved

Problem related to CString usage.

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

856 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