.Net assemly as a DLL for a win32 application

R

Rainer

Hello NG,

in a win32 UML Tool I can add a "expert" by providing a (windows32) dll.
I used to write these experts with Delphi (see code below).

Is it possible to write a similar "expert" usable from this win32 tool
with .Net and C# and if yes, where can I get hints and guids on how to
do that?

Thanks for any help!

Regards
Rainer

-------------------------------------------

library QMMEOpen;

uses
SysUtils,
Windows,
Forms,
Classes,
Dialogs,
QutronicExpertClasses in 'QutronicExpertClasses.PAS',
PrjNotify in 'PrjNotify.pas',
QutronicBaseExpert in 'QutronicBaseExpert.pas',
ExpertInterface in 'ExpertInterface.PAS',
InfoForm in 'InfoForm.pas' {QutronicInfoFrm},
QmmeMain in 'QmmeMain.pas' {FrmMain},
DiagramGrouping in 'DiagramGrouping.PAS',
Autodiagramming in 'Autodiagramming.PAS',
RQClasses in 'RQClasses.PAS',
MailBoxRq in 'MailBoxRq.pas',
TypeStream in 'TypeStream.PAS',
MMToolsApi in 'MMApi\MMToolsApi.PAS',
MMDiagramAPI in 'MMApi\MMDiagramAPI.PAS',
MMEngineDefs in 'MMApi\MMEngineDefs.pas',
ClassLocatorFrm in 'ClassLocatorFrm.pas' {ClassLocatorDlg},
QutronicDM in 'QutronicDM.pas' {DMQutronic: TDataModule},
MMVersioning in 'MMVersioning.pas';

{$R *.RES}

procedure InitializeExpert(const Srv: IMMToolServices); stdcall;
begin
// Copy interface pointer to initialize global var in MMToolsApi.pas
MMToolServices := Srv;
// Register the expert
Srv.AddExpert(TQutronicExpertInterface.Create);

// Adding a Project Notifier is not neccesary for most Experts, it's
included here for
// Demo purposes only
// Create a project notifier
ProjectNotifier := TProjectNotifier.Create;
// And Register an interface pointer
Srv.AddProjectNotifier(ProjectNotifier);

// now sync with parent window, if we omit this, modal dialogs won't
be really modal and
// modeless forms will behave even worse.
Application.Handle := Srv.GetParentHandle;
end;

procedure FinalizeExpert; stdcall;
begin
// there's no need to export this function is there's nothing to clean up
// In this demo expert all the cleaning-up is done by the
Expert.Destroyed
end;

function ExpertVersion: LongInt; stdcall;
begin
// This funciton and it's implementation are mandatory, if this
function is not
// exported or the version mismatches the version in ModelMaker, the
expert is not
// loaded
Result := MMToolsApiVersion;
end;

exports
InitializeExpert name MMExpertEntryProcName,
FinalizeExpert name MMExpertExitProcName,
ExpertVersion name MMExpertVersionProcName;

end.
 
P

Peter Duniho

Hello NG,

in a win32 UML Tool I can add a "expert" by providing a (windows32) dll.
I used to write these experts with Delphi (see code below).

Is it possible to write a similar "expert" usable from this win32 tool
with .Net and C# and if yes, where can I get hints and guids on how to
do that?

That depends on the Win32 tool. If I recall correctly, .NET provides a
way to wrap managed code in an unmanaged COM wrapper. So anything that
can deal with COM objects can use your managed code.

If the Win32 tool doesn't support COM objects as plug-ins, then another
approach would be to write an unmanaged wrapper yourself. I don't recall
the specifics, but there's a way for a unmanaged code to host an instance
of .NET, in which you can run managed code.

There may be other alternatives. What I know _won't_ work is simply
compiling your .NET code as a DLL and linking it to your Win32 tool or
loading it at run-time. So one way or the other, some kind of wrapper
will have to exist.

I'm pretty sure there was a thread in this newsgroup within the last 6-12
months on the topic. If you search the newsgroup with Google Groups,
looking for words like "managed dll unmanaged process", etc. you'll
probably find it. My recollection is that one of the people responding
provided some specifics about the COM wrapper technique.

Pete
 
J

Jakub Èermák

Hi,
The only way, how to make unmanaged exports in C# is by using the COM
wrapper - you can choose your assembly to be "COM-visible" and then you
should be somehow able to use it from unmanaged code as standard COM
library.
The second approach to this problem is to make your own wrapper in
C++/CLI (it's MSFT extension to normal C++ which adds things to handle
managed environment, it's quite messy IMO, because it basically contains
3 "worlds" in one language - C, C++ and .NET). The C++/CLI is very good
at calling managed code from unmanaged and vice versa, and you can make
a normal DLL that exports unmanaged functions (and calling managed code)
quite easily.
 
Top