|
-
Jul 10th, 2010, 05:54 AM
#1
Thread Starter
Member
[RESOLVED] Porting code from C++
I've been working on porting code over from C++, I ported most of the code but I can't seem to manage to get part of it done.
Code:
IntPtr m_MapFile;
IntPtr m_MapAddress;
MMFTextControlMapping m_TCM;
Queue<MMFTextCommand> m_QueuedCommands;
public CTextHelper(string name)
{
m_MapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, true, name);
if (m_MapFile == null)
{
return;
}
m_MapAddress = MapViewOfFile(m_MapFile, // handle to mapping object
FILE_MAP_ALL_ACCESS, // read/write permission
0, // max. object size
0, // size of hFile
0); // map entire file
if (m_MapAddress == null)
{
return;
}
m_TCM = (MMFTextControlMapping*)m_MapAddress; // this is the part of the code I can't figure out how to port
}
Any help would be appreciated, the line if I can't port is: m_TCM = (MMFTextControlMapping*)m_MapAddress;.
-
Jul 10th, 2010, 07:24 AM
#2
Re: Porting code from C++
Are you getting an error when porting it over?
-
Jul 10th, 2010, 09:41 PM
#3
Thread Starter
Member
Re: Porting code from C++
Code:
Cannot take the address of, get the size of, or declare a pointer to a managed type ('MMFKeyboardControlMapping')
This is the error I get, MMFKeyboardControlMapping is a struct.
-
Jul 10th, 2010, 10:04 PM
#4
Re: Porting code from C++
Why do you need a pointer to this object? What do you intend to do with it? If you really need a pointer in your C# code then you must allow unsafe code in your project and create an unsafe block. If you need a pointer for unmanaged code then you can use Marshal.StructureToPtr. Most likely you don't actually need a pointer though, but we really can't say unless we know what you want to do.
-
Jul 10th, 2010, 11:44 PM
#5
Thread Starter
Member
Re: Porting code from C++
It's not that I need the pointer, but I have no idea how to do it in C#. The commented code you see there is still C++, I'm trying to use Memory Mapped Files.
-
Jul 11th, 2010, 12:05 AM
#6
Re: Porting code from C++
Looking at your code more closely, I see that m_MapAddress is an IntPtr. At a guess, I'd say that you should use Marshal.PtrToStructure to turn that IntPtr into a MMFTextControlMapping structure instance. I say that it's a guess because all you've done so far is posted some code and said you can't convert it. You made no attempt to explain the code or what you're actually trying to achieve, so we have to guess and make assumptions.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|