?
Solved

LPSTR to LPCTSTR

Posted on 1999-01-28
5
Medium Priority
?
1,456 Views
Last Modified: 2013-12-03
If the parameter of function is LPCTSTR, how can I pass a variable typed LPSTR to it ?

Andrew
0
Comment
Question by:andrewyu
  • 2
  • 2
5 Comments
 
LVL 31

Accepted Solution

by:
Zoppo earned 0 total points
ID: 1419419
You can call the function as is, because LPSTR is typedef'd as 'char*' and LPCTSTR as 'const char *', which does not need any expilcit type casting. I.E.

CString str = "Hello, world...";
LPSTR search = ",";
CString subStr = str.SpanExcluding( search );// expects LPCTSTR but needs no cast

ZOPPO
0
 
LVL 86

Expert Comment

by:jkr
ID: 1419420
When you don't use UNICODE, simply typecast it. If not, you'll have to convert it into a UNICODE string first:

LPCTSTR ANSI2UNICODE (char*    pszANSI)
{
static TCHAR awc[ MAX_SIZE];

MultiByteToWideChar ( CP_ACP,
0,
pszANSI,
-1,
awc
lstrlen (pszANSI) + 1
);

return ( awc);
}
0
 

Author Comment

by:andrewyu
ID: 1419421
Maybe I rather ask you in more direct way.

Actually, I want to pass a variable typed LPSTR of  hFile to bcp_init ? It seems that it cannot work, so, any problem in it ?

Andrew
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 1419422
Can you specify 'it seems that it cannot work' a bit more detailed?
Do you get compiler or linker errors or does your code crash or hang?
Perhaps you could also add a small code fragment.

ZOPPO
0
 

Author Comment

by:andrewyu
ID: 1419423
I think it cannot see the parameter !

Andrew
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

809 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