List Info

Thread: load a .NET assembly from a Delphi win 32 application without COM




load a .NET assembly from a Delphi win 32 application without COM
user name
2006-04-19 08:14:52
Hello,

Is there a way to load a .NET assembly from a Delphi win 32 application without using COM?
I've found things like MSCOREE.DLL, ClrCreateManagedInstance and CorBindToRuntimeEx, but i can't put them together to get them working.


This is what i've got so far:

unit Unit3;

interface

type
  InxInterface = Pointer;

  TClrCreateManagedInstance = function(aTypeName: PWideChar; const aInterface: TGUID; out aObject):
    HRESULT; stdcall;

function LoadManagedClass(aClassName, anAssemblyName: ShortString; const aInterface: TGUID): InxInterface; stdcall; Export;

implementation

uses
  sysutils, stdctrls, windows, Dialogs;

function LoadManagedClass(aClassName, anAssemblyName: ShortString; const
  aInterface: TGUID): InxInterface; stdcall; export;
var
  netClass: WideString;
  assembly: Integer;
  ClrCreateManagedInstance: TClrCreateManagedInstance;
  dllInst: HINST;
begin
  result := nil;
  assembly := -1;
 ; anAssemblyName := ExtractFileName(anAssemblyName);

  netclass := aClassName + ', ' + anAssemblyName;

  dllInst := LoadLibrary('mscoree.dll');
&nbsp; if dllInst <> 0 then
&nbsp; begin
&nbsp; //GetProcAddress(dllInst, 'CorBindToRuntimeEx')
 &nbsp;  ClrCreateManagedInstance := TClrCreateManagedInstance(GetProcAddress(dllInst, 'ClrCreateManagedInstance'));

{ the dllInst does return a valid value
GetProcAddress(dllInst, 'ClrCreateManagedInstance') does return nil
}
&nbsp; &nbsp; if assigned(ClrCreateManagedInstance) then
&nbsp; &nbsp; &nbsp; assembly := ClrCreateManagedInstance(PWideChar(netclass), aInterface, Result);
  end;
&nbsp; if assembly <> 0 then
&nbsp; 
end;

end.

So the dll is loadeds, but 'ClrCreateManagedInstance' is noit found.

Any suggestions, or even better a sample code would be appreciated.

Regards

Andries

 ; &nbsp; &nbsp;  &nbsp; &nbsp; 
---------------------------------
Blab-away for as little as 1¢/min. Make  PC-to-Phone Calls using Yahoo! Messenger with Voice.

[Non-text portions of this message have been removed]

load a .NET assembly from a Delphi win 32 application without COM
user name
2006-04-19 12:06:21
Hi Andries!
  I m also looking for same.
&nbsp; I want to use .net assembly in delphi for win32 application.
  Do you have any info on this topic to share.
&nbsp; I m doing this by creating c# dll,provide strong name, register this assembly and the created tlb of it. and using that tlb.
&nbsp; it goes ok but the problem is i can instantiate object of my c# class, access method,
&nbsp; but while running it gives an Access violation error.
&nbsp; can u help me to get rid of this problem.
  Thanks
&nbsp; 
  with regards
&nbsp; Bijal

Andries Bos <andriesbosyahoo.com&gt; wrote:
&nbsp; Hello,

Is there a way to load a .NET assembly from a Delphi win 32 application without using COM?
I've found things like MSCOREE.DLL, ClrCreateManagedInstance and CorBindToRuntimeEx, but i can't put them together to get them working.


This is what i've got so far:

unit Unit3;

interface

type
&nbsp; InxInterface = Pointer;

  TClrCreateManagedInstance = function(aTypeName: PWideChar; const aInterface: TGUID; out aObject):
 &nbsp;  HRESULT; stdcall;

function LoadManagedClass(aClassName, anAssemblyName: ShortString; const aInterface: TGUID): InxInterface; stdcall; Export;

implementation

uses
  sysutils, stdctrls, windows, Dialogs;

function LoadManagedClass(aClassName, anAssemblyName: ShortString; const
&nbsp; aInterface: TGUID): InxInterface; stdcall; export;
var
  netClass: WideString;
  assembly: Integer;
  ClrCreateManagedInstance: TClrCreateManagedInstance;
&nbsp; dllInst: HINST;
begin
  result := nil;
&nbsp; assembly := -1;
 ; anAssemblyName := ExtractFileName(anAssemblyName);

  netclass := aClassName + ', ' + anAssemblyName;

&nbsp; dllInst := LoadLibrary('mscoree.dll');
&nbsp; if dllInst <> 0 then
&nbsp; begin
&nbsp; //GetProcAddress(dllInst, 'CorBindToRuntimeEx')
 &nbsp;  ClrCreateManagedInstance := TClrCreateManagedInstance(GetProcAddress(dllInst, 'ClrCreateManagedInstance'));

{ the dllInst does return a valid value
GetProcAddress(dllInst, 'ClrCreateManagedInstance') does return nil
}
&nbsp; &nbsp; if assigned(ClrCreateManagedInstance) then
&nbsp; &nbsp; &nbsp; assembly := ClrCreateManagedInstance(PWideChar(netclass), aInterface, Result);
  end;
&nbsp; if assembly <> 0 then
&nbsp; 
end;

end.

So the dll is loadeds, but 'ClrCreateManagedInstance' is noit found.

Any suggestions, or even better a sample code would be appreciated.

Regards

Andries

 ; &nbsp; &nbsp; &nbsp; &nbsp;  
---------------------------------
Blab-away for as little as 1¢/min. Make  PC-to-Phone Calls using Yahoo! Messenger with Voice.

[Non-text portions of this message have been removed]



-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: delphi-en-unsubscribe@yahoogroups.com


&nbsp; &nbsp;
---------------------------------
  YAHOO! GROUPS LINKS

   ;
 &nbsp;  Visit your group "delphi-en" on the web.
&nbsp; &nbsp;
 &nbsp;  To unsubscribe from this group, send an email to:
delphi-en-unsubscribe@yahoogroups.com
&nbsp; &nbsp;
 &nbsp;  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

   ;
---------------------------------
 



&nbsp; &nbsp;    &nbsp; &nbsp;   &nbsp; &nbsp;   &nbsp; &nbsp; 
---------------------------------
Jiyo cricket on Yahoo! India cricket
Yahoo! Messenger Mobile Stay in touch with your buddies all the time.

[Non-text portions of this message have been removed]

[1-2]

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