The three virtues of a programmer: Laziness, Impatience, and Hubris. – Larry Wall

Legacy:Setting Up VCPlusPlus/The CPP File

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search

In your C file, include the following:

# both from the unreal public sources
#include "core.h"
#include "engine.h"
 
# the include that was generated by ucc
#include "$UNREALDIR\SQLite\Inc\SQLiteClasses.h"

Strangely enough, the macro IMPLEMENT_PACKAGE doesn't do what it's supposed to do. Instead, add the following line next: (replacing HCSQLIB with the name of your package)

extern "C" DLL_EXPORT TCHAR GPackage[];
DLL_EXPORT TCHAR GPackage[] = TEXT("HCSQLIB");

Then, tell unreal which class(es) this file is implementing. Use

IMPLEMENT_CLASS(ASQLITEFile);

Third, tell unreal which functions you're implementing:

Replace PACKAGE with the name of your package, ID with a UNIQUE number for static functions, or -1 for non-static functions. FUNCTION is the name of your function, prefixed with exec.

IMPLEMENT_FUNCTION(PACKAGE, ID, FUNCTION);

Next, since you didn't use IMPLEMENT_PACKAGE (which doesn't work), you'll have to define your own DLL entry point yourself.

BOOL __stdcall DllMain(HINSTANCE hInInstance, DWORD dwCallType, LPVOID lpPretendIDontExist)
{
  if(dwCallType == DLL_PROCESS_ATTACH)
  {
    // initialize your dll
    hInstance = hInInstance;
  }
  else if(dwCallType == DLL_PROCESS_DETACH)
  {
    // do some cleanup
  }
  return TRUE;

Finally, your function:

Note that the parameters are the same for all functions, no matter what parameters are defined in the corresponding .uc file. See the native coding reference for more information about how to obtain parameters. Also note that the variables s1, i1 and i2 are defined by the macros P_GET_STR and P_GET_INT automatically. The guard and unguardexec macros actually create a try..catch block.

This function takes a string and two integers as parameters and returns the product of the two integers.

void
MyPackage::execTest(FFrame& Stack, RESULT_DECL)
{
  guard(MyPackage::execTest);
  P_GET_STR(s1);
  P_GET_INT(i1);
  P_GET_INT(i2);
  P_FINISH;
 
  (*(DWORD*)Result) = i1 * i2;
 
  unguardexec;
 
 
}

The according unrealscript function would look like this:

native function int Test(string sStringThatIsIgnored, int iFactor1, int iFactor2);