?
Solved

LPSTR to LPCTSTR

Posted on 1999-01-28
5
Medium Priority
?
1,426 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
[X]
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
  • 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

762 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