List Info

Thread: (




(
user name
2006-05-18 05:28:51

i'm using a Dll wrote in C++Builder.
I'm growing that Dll (i mean i have the source code of the Dll, so i can
manipulate it).

I wanted to add in the call of a function of Dll a "pointer to method",

(for example :

typedef __stdcall void (__closure *TmyMethod)(int,int);

#define NO_MAGLE extern "C"
#define DLL_EXPORT __declspec(dllexport)
#define DLL_PORT NO_MANGLE DLL_EXPORT

DLL_PORT __stdcall void FuncDll(TmyMethod F){
 ;   ....
    F(1,2);
    ....
}

)

but i didn't want to trust that C++Builder and Delphi use the same way to
manipulate TMethod (and similars), so i semplified the type of pointer using
a:

typedef __stdcall void (*TmyProcedureCallingMethod)(int,int,void * PMethod);

DLL_PORT __stdcall void FuncDll(TmyProcedureCallingMethod P,void * PMethod){
    ....
    P(1,2,PMethod);
    ....
}

and (in Delphi)

<<

type TMyMethod = procedure(a : integer;b : integer) of object;
type PTMyMethod = ^TMyMethod;

procedure aMyProcedure(a : integer;b : integer;PM : PTMyMethod); stdcall;
begin
&nbsp; &nbsp; PTMyMethod^(a,b);
end;

calling the Dll function in this way:

&nbsp; &nbsp; ...
 ; &nbsp; FuncDll(aMyObject.aMyMethod);
 &nbsp;  ...

>;>

Well, before to use this way to work, i tried a little code avoiding the
Dll, to check how
to use the pointers to methods, to make it "traveling" fine between
functions, so i just used a
little code in delphi. In fact all worked already fine with other types of
pointers (between Delphi
and my Dll) that i had to use in the last days.

The little experimental code in Delphi is :


....

procedure TForm1.App(a : integer);
var pSelf : Pointer;
begin
&nbsp;  pSelf := Self; //only for debug goal

&nbsp;  if (Self.Height < 543) or (pSelf = Pointer(52)) then
&nbsp; &nbsp; &nbsp; Self.Height := Self.Height div 2;
end;

type TP = procedure(a : integer) of object;
type P_TP = ^TP;

procedure TForm1.Button1Click(Sender: TObject);
var
 ;  m : procedure(a : integer) of object;
&nbsp;  a : integer;
  ; m1 : P_TP;
begin
 &nbsp; App(0); //for debug goal
&nbsp;  m := App;
&nbsp;  m1 := m;
   a := 1027;

&nbsp;  m(0);

&nbsp;  P_TP(m1)^(a); //this call raises an exception.
end;

....

Like you can see, in this experimental code i don't use the Dll.
I wanted just build a little experience about pointers to methods in Delphi,
because i knew them better in C++, but not in delphi.
My probelm is that the call P_TP(m1)^(a); raised an expection.

I hope i could be more clear this time.

Thank you,
Mauro Russo.


----- Original Message -----
From: "Walter Prins"; <wprinsgmail.com&gt;
To: <delphi-en@yahoogroups.com>;
Sent: Thursday, May 18, 2006 12:56 AM
Subject: [delphi-en] Re: :(


&gt; We don't want you to "limit" the question, we want you to explain *what*
&gt; you're trying to achieve big picture as well as *why* if possible.
> You're asking us to solve what *you* think is the problem in your
> current approach to the problem.&nbsp; However, this may not be the real
> problem or the best solution, or your approach may be fundamentally
> flawed or whatever.&nbsp; Hence why you must explain in more detail why
> you're doing what you're doing, and what all the code is intended to do
> in order for us to be able to have a chance of sensibly helping you..
>;
> Things that I'm wondering is, what dll are you trying to call, what's it
> meant to do, what the C/C++ header/interface declaration for the method
&gt; you want to call etc.
>
>
>; Mauro Russo wrote:
&gt; > No one answer to me?
> >
> > Please, i really need to make it working.
> > In my last e-mail i boundered the question.
> >
> >
>
>
>;
> -----------------------------------------------------
> Home page: http://groups.yahoo.com/group/delphi-en/
> To unsubscribe: delphi-en-unsubscribe@yahoogroups.com
> Yahoo! Groups Links
>;
>
&gt;
>
&gt;
>
>

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )