Create a File in C# and pass it as an IntPtr to a COM object

c#, com, file, pointers, windows

Solution

You're a little vague as to what you have to pass in as the "file"- if you have a FileStream you can hand in FileStream.Handle as the IntPtr (assuming its expecting a HANDLE value)

See "How to pass parameters of Type HANDLE from C# to C++ DLL".

Problem

I'm working with some COM objects in C#, one of them has a function called SetLogFile that takes an IntPtr. How can I create the file in C# then pass it as an IntPtr to that COM function? EDIT: The function requires an open file handle: http://msdn.microsoft.com/en-us/library/aa915939.aspx

Original source