dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Relational Databases
Expertise: Beginner
Mar 28, 1997

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Putting a char into a Pchar

Question:
I'm using the Winexec command and trying to use a string as the argument, but Winexec takes only a Pchar as its argument. I can't figure out how to put a regular string into a Pchar, or how to make a Pchar 'point' to a character string.

Answer:
WinAPI calls can be pretty confusing, huh? Let's say you have a function called WinAPICall that takes a PChar as an argument. Here are a couple of ways to make the call: First Method (This will only work for Delphi 2.0, which supports casting):

WinAPICall(PChar(MyStringVal));
Second Method:
procedure CallWinApiCall(S : String);
var
  Val  : String;
  pVal : PChar;
begin
  Val := S;
  {Initialize memory for the PChar}
  GetMem(pVal, Length(Val));

  {Copy the contents of Val to PChar}
  pVal := StrPCopy(pVal, Val);
  WinAPICall(pVal);
  
  {This next step is ABSOLUTELY necessary}
  FreeMem(pVal, Length(Val));
end;  
In any case, that should do it for you pretty nicely.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date