PDA

View Full Version : I have a problem.



detvog
05-03-2008, 01:01 PM
System: Windows XP
Compiler: Delphi 2005
Libraries:

Hi, can anyone help me ?

I have 2 functions in a c++ dll and will them use from delphi.

1. c++

void DLL_Export SetWindowCaption( const wchar_t * wcptrtext)
{ setwindowcaption(wcptrtext);
}

delphi: procedure SetWindowCaption(const ca: pwidechar);cdecl;
external dllname;
SetWindowCaption('Test'); ---> this works

2. c++

void DLL_Export GetTexture(char * cptrFile)
{ return (void *) ....->gettexture(cptrFile);
}

delphi: function GetTexture(const name: pwidechar):texture;
external dllname
tex:=GetTexture('logo.bmp'); ------->DO NOT WORK
the dll do not found the bitmap :roll:

i think the transfer from 'name' is not ok .


Sorry for my bad english.

JSoftware
05-03-2008, 01:55 PM
You should probably use the cdecl directive

chronozphere
05-03-2008, 02:01 PM
First... It's better to put your code between [ CODE ] or [ PASCAL ] tags. It makes your post more readable. :)

Secondly.. why do you call your thread "I have a problem". I think that violates the "Help me" forum rules. You better use a name like "Cannot transfer a string to a C++ DLL" or something like that.

Okay... your problem:

I'm not a C++ hero, but i think Char* is the not a widechar pointer. You should try to define your function like this:


function GetTexture(const name: pChar):texture; cdecl; external dllname;


Sometimes.. DLL's use STDCALL instead of CDECL but you should try CDECL first. :)

Hope that helps ;)

detvog
05-03-2008, 05:01 PM
chronozphere ok.


Boah....i have found the error. I have 'cdecl' forgotton in my function. :roll: :oops:







Sorry for my english