CharToOem - error

When I use the CharToOem function it raise a Kernel32.dll access violation.

My sourcecode looks something like this.

Var
  text : string;

Begin
  CharToOem (PChar(text),PChar(text));
End;

How can I prevent the error?

Thanking you ín anticipation
Preben Holm
GrebenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LischkeCommented:
Hi Preben,

have you allocated memory for the text? Although I do a lot with languages and character conversion I still don't know what they mean with OEM charset. Can it be that the resulting text is larger than the original text (keyword: MBCS)?

Ciao, Mike
0
dvodCommented:
This code from RX Library

function StrToOem(const AnsiStr: string): string;
{$IFNDEF WIN32}
var
  Src, Dest: array[0..255] of Char;
{$ENDIF}
begin
  SetLength(Result, Length(AnsiStr));
  if Length(Result) > 0 then
{$IFDEF WIN32}
    CharToOem(PChar(AnsiStr), PChar(Result));
{$ELSE}
  begin
    StrPCopy(Src, AnsiStr);
    AnsiToOem(Src, Dest);
    Result := StrPas(Dest);
  end;
{$ENDIF}
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MadshiCommented:
Hi Preben,

I don't know why you're getting an exception. I'm doing the same as you do since several years without any problems. Have you tried it on several computers? Perhaps your Windows installation is corrupt? Or do you give in mega strange text?   :-)

Mike,

this function converts dos texts into Windows texts. E.g. if you read in autoexec.bat, you see strange characters for "ö, ü, ä". If you use OemToChar before showing the text everything is fine.

Regards, Madshi.
0
LischkeCommented:
Thanks Madshi, but it is still irritating because it is not clear that the DOS code page is meant when speaking of an OEM code page. But obviously it is so...

Ciao, Mike
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.