Help with code that won't compile?

Apologies in advance for my limited experience with c++ (I'm learning).

I'm writing a dll that needs to return an array of ints to the calling application. I have sample code (provided by the application's docs) for doing this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "stdafx.h"
#include <stdio.h>
#include <assert.h>

template<typename DataType>
struct TArray
{
	DataType* Data;

	int Num()
	{
		return ArrayNum;
	}

	void Reallocate(int NewNum, bool bCompact=false)
	{
		ArrayNum = NewNum;
		if( ArrayNum > ArrayMax || bCompact )
		{
			ArrayMax = ArrayNum;
			Data = (DataType*)(*ReallocFunctionPtr)( Data, ArrayMax * sizeof(DataType), 8);
		}
	}
private:
	int ArrayNum;
	int ArrayMax;
};

struct MyNavigationStruct
{
	TArray<int> NavigationData;
};


extern "C"
{
	typedef void* (*ReallocFunctionPtrType)(void* Original, DWORD Count, DWORD Alignment);

	ReallocFunctionPtrType ReallocFunctionPtr = NULL;

	struct FDLLBindInitData
	{
		INT Version;
		ReallocFunctionPtrType ReallocFunctionPtr;
	};

	__declspec(dllexport) void DLLBindInit(FDLLBindInitData* InitData)
	{
		ReallocFunctionPtr = InitData->ReallocFunctionPtr;
	}

	__declspec(dllexport) void GetNavData(struct MyNavigationStruct* NavData)
	{
		NavData->NavigationData.Reallocate(1000);

		for( int i=0;i<1000;i++ )
		{
			NavData->NavigationData.Data[i] = i;
		}
	}
}


When I open the example solution in Visual Studio it compiles fine. However when I paste this code into a file in my solution, it fails to compile, stating that:

C2065 'ReallocFunctionPtr': undeclared identifier


Which is referring to this line 21 in the Reallocate() function:
 
Data = (DataType*)(*ReallocFunctionPtr)( Data, ArrayMax * sizeof(DataType), 8);

There is no custom header file in the example solution. So I can't understand why it is compiling fine in the example solution and not in my own solution.

Any help or tips would be very appreciated.

Last edited on
Turns out I needed to change the setting under the Property Pages -> C/C++ -> Language -> Conformance mode from:

Yes (/permissive-)

to

Default
Last edited on
Topic archived. No new replies allowed.