Solved

LPSTR to LPCTSTR

Posted on 1999-01-28
5
1,405 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 Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studio Debugging 3 160
Best way to accomplish this task? 3 96
Using MS Code on my Mac 6 76
PL SQL Developer 7 87
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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