Game Development Reference
In-Depth Information
public static extern int GetNumActors();
[DllImport(editorDllName, CallingConvention = CallingConvention.Cdecl)]
public unsafe static extern void GetActorList(IntPtr actorIdArrayPtrAddress,
int size);
[DllImport(editorDllName, CallingConvention = CallingConvention.Cdecl)]
public unsafe static extern int GetActorXmlSize(uint actorId);
[DllImport(editorDllName, CallingConvention = CallingConvention.Cdecl)]
public unsafe static extern void GetActorXml(IntPtr actorXMLPtrAddress,
uint actorId);
[DllImport(editorDllName, CallingConvention = CallingConvention.Cdecl)]
public unsafe static extern int PickActor(IntPtr hWndPtrAddress);
// Actor modification functions
[DllImport(editorDllName, CallingConvention = CallingConvention.Cdecl)]
public static extern int CreateActor([MarshalAs(UnmanagedType.BStr)]
string lactorResource);
[DllImport(editorDllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void ModifyActor([MarshalAs(UnmanagedType.BStr)]
string lactorModXML);
[DllImport(editorDllName, CallingConvention = CallingConvention.Cdecl)]
public unsafe static extern void DestroyActor(uint actorId);
}
There are a few things you should notice. First, the DLL to be loaded is explicitly
declared. Next, [DllImport(editorDllName, CallingConvention = Calling
Convention.Cdecl)] is declared prior to the function. The DllImport attribute
imports the function from the DLL, and it matches the export declarations in the
C++ code you saw previously. This is part of the Platform Invocation Services, or
PInvoke. Next, all of these functions are declared unsafe . The C++ game engine
runs in unmanaged code, which basically means there is no memory tracking, gar-
bage collection, and other safety systems built into the CLR. That
'
s why this code is
declared unsafe.
Program Class
The Program class is the entry point of the C# application.
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace EditorApp
{
static class Program
 
 
Search WWH ::




Custom Search