Solved

LPSTR to LPCTSTR

Posted on 1999-01-28
5
1,387 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

815 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

13 Experts available now in Live!

Get 1:1 Help Now