[M3devel] Building DLLs for Win32 (NT386MINGNU)

Jay jay.krell at cornell.edu
Thu Mar 5 16:52:46 CET 2009


 > From: rv82 at ya.ru 
 > To: jay.krell at cornell.edu 
 > Subject: Re: [M3devel] Building DLLs for Win32 (NT386MINGNU)  
 > Date: Thu, 5 Mar 2009 07:44:16 +0300 
 > 
 > And, Is it possible to use DLLs built with other languages? For example, 

 > may I import DLL built by C in Modula-3 program? 


Definitely..just perhaps not stuff built with Cygwin (nothing to do with Modula-3, interop with Cygwin is slightly difficult even for C code built with another compiler/runtime).

 

Basically, you have to rewrite your headers in Modula-3.

 Modula-3 "headers" are ".i3" files -- i for interface, 3 for Modula-3.

And either LoadLibrary/GetProcAddress, or have an import .lib.

In the Modula-3 you mark the functions with an "external" "pragma".

 

Large example:

http://modula3.elegosoft.com/cgi-bin/cvsweb.cgi/cm3/m3-libs/m3core/src/win32/WinBase.i3?rev=1.7;content-type=text%2Fplain

 

small example..

 

There were some nice small examples in the Critical Mass product.
I can't find them online.

Maybe...


http://modula3.elegosoft.com/cm3/doc/index.html

has a link "CM3 Examples" to http://modula3.elegosoft.com/cm3/doc/example/
but it doesn't work.

 

 

I know this is kind of difficult to understand..but think about this..the Modula-3 compiler and runtime are written in Modula-3. They work. They read and write files, create threads, etc. -- they use the underlying system, which is composed of .dlls, which aren't written in Modula-3. Therefore, the answer to your question must be "yes". They call into the underlying system from Modula-3 using the same techniques as you would use. Of course, you also want to know how to do it, which this thought exercise does not immediately reveal -- you'd have to look at the compiler/runtime, find the calls to open files, etc., and trace them down. You would in fact eventually get to this WinBase.i3 file and its CreateFile declaration, but it takes searching through a few layers. Another thing you can do is run the compiler under a debugger and break on CreateFile (CreateFileA, CreateFileW) and look at the stack, and the file names on it. That can speed the search significantly. Oh, and WinBase.i3 wouldn't be on the stack, as the way it works, these declarations let other Modula-3 code call directly into the underlying system, without a "wrapper". (Well, lately I have been adding wrappers, for a good reason, but that is another matter.)

 

 

Um, why do you favor NT386MINGNU/mingw over NT386/Visual C++? There is a free "beer" download, the "Express Edition", which should work. Have you tried that? I know there are reasons but I'm curious to know what yours are.

 

 


 - Jay

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20090305/9f59b6c3/attachment-0002.html>


More information about the M3devel mailing list