PC Review


Reply
Thread Tools Rate Thread

CLR and CreateFile w/ FILE_FLAG_DELETE_ON_CLOSE

 
 
knattetjatte@googlemail.com
Guest
Posts: n/a
 
      29th Aug 2008
Hi Group,

I have a program which loads a dll and executes a method in it. The
library it is loaded from is marked with delete-on-close. This worked
fine.

Then I introduced a .NET mixed-mode dll with the same interface, and
then it does not work anymore. The CLR throws an FileLoadException
upon the invocation of the method complaining about a file being used
by another process.

...anyone know of any information about this or even better, a
workaround?

Here is the complete code to reproduce it:

native.cpp (compile: cl /LD native.cpp):
extern "C" _declspec(dllexport) void green_version() { }

il.cil (compile: ilasm /dll /output=meep.dll il.cil):
..assembly meep {}
..method public static void green_version() cil managed
{
.export [1]
ret
}

main.cpp (compile: cl main.cpp):
#include <windows.h>
#include <stdio.h>
void load_and_run(char *dll)
{
HANDLE h = CreateFile(dll, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_FLAG_DELETE_ON_CLOSE, NULL);
if (h == INVALID_HANDLE_VALUE)
exit(1);

HANDLE foo = LoadLibrary(dll);
if (!foo)
exit(3);

typedef void (WINAPI *funcs_t)(void);
funcs_t func = (funcs_t)GetProcAddress((HMODULE)foo,
"green_version");
func();
}

int main(int argc, char **argv)
{
if (!LoadLibrary("mscoree.dll"))
exit(1);
// works fine:
load_and_run("native.dll");
// does not work
load_and_run("meep");

return 0;
}

Thanks to anyone who read all the way down to here

/gk
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Createfile error help Paul M Windows XP General 4 8th Jul 2010 03:40 PM
CreateFile() and usb mike Windows XP Drivers 0 16th Sep 2006 06:14 PM
CreateFile JLW Microsoft C# .NET 4 9th Jun 2004 04:43 PM
vb.net's CreateFile Stephen Remde Microsoft VB .NET 8 10th Nov 2003 12:24 PM
Re: USB and CreateFile Rob Microsoft Windows 2000 0 3rd Sep 2003 11:04 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:51 AM.