> Declare FILE as a struct not class, change all int16 to int. Now "FILE* xxx"
> parameters, should become "ref FILE xxx".
Hi, [Inline]
> > Declare FILE as a struct not class, change all int16 to int. Now "FILE*
> xxx"
> > parameters, should become "ref FILE xxx".
>
> Unfortunately .NET will not accept struct as return type - that kind of
> P/Invoke method declaration is not supported now.
Yes, I know. When did I say you need to do that ? Just use an IntPtr as
return type and if you wish to get the FILE struct, then declare it as a
struct. You can use Marshal.PtrToStruct to get the struct. Then use ref
FILE as parameter type for functions that need a FILE*.
> Furthermore, my understanding is that C type int is just 2 bytes in size and
> corresponds to Int16 of any CLI implementation.
It's my understanding that an int has the width of the databus, which is
4bytes on a 32 bit platform (eg. win32).
> > If you don't need the FILE structure yourself, you could just use an
> IntPtr
[quoted text clipped - 7 lines]
> that pointer passed to that call is treated by C-Runtime functions as a
> _FILEX pointer and not FILE pointer - this leads to exception being thrown
Don't know what's going on here, but it doesn't have anything to do with the
c# prototypes, pointers are untyped, so if you pass it as ref FILE or IntPtr
that's just the same, it's just an address.
It's considered a _FILEX pointer because it's not in some table, maybe two
msvcr71d.dll's are instantiated, and passing FILE* between them would cause
this problem, but I admit it's a guess. If that's the problem then try
creating a wrapper dll that does both opening/closing files aswell as
calling your 3th party dll and call only the wrapper dll from c#.
HTH more,
greetings
> at : EnterCriticalSection( &(((_FILEX *)pf)->lock) );
> the code below comes from file.c source for msvcr71d.dll. The externale
[quoted text clipped - 72 lines]
> > > FILE f = (FILE) Marshal.PtrToStructure(pf, typeof(FILE));
> > > int result = Utilities.fclose(f);
BMermuys - 21 Jul 2004 03:08 GMT
> Yes, I know. When did I say you need to do that ? Just use an IntPtr as
> return type and if you wish to get the FILE struct, then declare it as a
> struct. You can use Marshal.PtrToStruct to get the struct. Then use ref
> FILE as parameter type for functions that need a FILE*.
Correction:
You can marshal the pointer to struct, but you must always pass the IntPtr
you got from opening the file as an IntPtr for FILE* parameters and not as
ref FILE.
greetings
> > Furthermore, my understanding is that C type int is just 2 bytes in size
> and
[quoted text clipped - 106 lines]
> > > > FILE f = (FILE) Marshal.PtrToStructure(pf, typeof(FILE));
> > > > int result = Utilities.fclose(f);
Jacek - 24 Jul 2004 09:41 GMT
Hello!
Thanks a lot for help - I fixed error by using newer version of external
dll - most probably it was their bug ;)
Jacek
> > Yes, I know. When did I say you need to do that ? Just use an IntPtr as
> > return type and if you wish to get the FILE struct, then declare it as a
[quoted text clipped - 123 lines]
> > > > > FILE f = (FILE) Marshal.PtrToStructure(pf, typeof(FILE));
> > > > > int result = Utilities.fclose(f);
Jacek - 24 Jul 2004 10:42 GMT
Hello!
Your were right supposing that two different C Run-Time libraries were
used - one by external dll and the other by my managed dll with P/Invoke
code.
As a result pointer types and functions were mixed and working properly. New
library is linked with currently used by me msvcrt71.dll and everything is
working fine.
> It's my understanding that an int has the width of the databus, which is
> 4bytes on a 32 bit platform (eg. win32).
Not true, it would depend on compiler used i.e. gcc 3.3.3 would create 32
bit C int on x86_64 machines.
Cheers
Jacek
> Hi, [Inline]
>
[quoted text clipped - 117 lines]
> > > > FILE f = (FILE) Marshal.PtrToStructure(pf, typeof(FILE));
> > > > int result = Utilities.fclose(f);
BMermuys - 24 Jul 2004 15:58 GMT
Hi,
> Hello!
>
[quoted text clipped - 4 lines]
> library is linked with currently used by me msvcrt71.dll and everything is
> working fine.
Glad its working now.
> > It's my understanding that an int has the width of the databus, which is
> > 4bytes on a 32 bit platform (eg. win32).
>
> Not true, it would depend on compiler used i.e. gcc 3.3.3 would create 32
> bit C int on x86_64 machines.
Right, from what I read the int should be "the most natural and fastest
datatype" on a processor but this can be vague and it is the compiler that
makes the final decission. Don't quote me though.
Greetings
> Cheers
>
[quoted text clipped - 127 lines]
> > > > > FILE f = (FILE) Marshal.PtrToStructure(pf, typeof(FILE));
> > > > > int result = Utilities.fclose(f);