Solved

LPSTR to LPCTSTR

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

Accepted Solution

by:
Zoppo earned 0 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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 30

Expert Comment

by:Zoppo
Comment Utility
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
Comment Utility
I think it cannot see the parameter !

Andrew
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

763 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

6 Experts available now in Live!

Get 1:1 Help Now