I get these three errors and they seem to make little sense to me. If i comment the UserInstruction1(P1, P2, P3); in the console app the errors go away. Both projects are /CLR projects.
error LNK2028: unresolved token (0A000930) "void __cdecl UserInstruction1(double *,wchar_t *,wchar_t *)" (?UserInstruction1@@$$FYAXPANPA_W1@Z) referenced in function "int __cdecl wmain(int,wchar_t * * const)" (?wmain@@$$HYAHHQAPA_W@Z)
error LNK2019: unresolved external symbol "void __cdecl UserInstruction1(double *,wchar_t *,wchar_t *)" (?UserInstruction1@@$$FYAXPANPA_W1@Z) referenced in function "int __cdecl wmain(int,wchar_t * * const)" (?wmain@@$$HYAHHQAPA_W@Z)
error LNK1120: 2 unresolved externals C:\Workspace\Company.Pins\Bank\Source\Debug\Company.Pins.Bank.Win32Console.exe
//Console App.
#include "stdafx.h"
#include "UInstruction.h"
int _tmain(int argc, _TCHAR* argv[])
{
auto P2 = (TCHAR *)"3 Barrowstead";
TCHAR* P3;
double* P1;
P1[0] = 13;
UserInstruction1(P1, P2, P3);
return 0;
}
—
//UInstruction.h
#ifndef __UINSTRUCTION_H__
#include "stdafx.h"
#include "UInstruction.h"
#include "common.h"
#include <iostream>
#include <stdio.h>
#define PRES_NOCOMMAND_FOUND 2000
#define DllExport __declspec(dllexport)
void ReconcileUHParameter(const double* lpNumeric, TCHAR* lpAlpha1, TCHAR* lpAlpha2);
extern void UserInstruction1(double* lpNumeric, TCHAR* lpAlpha1, TCHAR* lpAlpha2);
#endif
—
//UInstruction.cpp
#include "stdafx.h"
#include "UInstruction.h"
#include "common.h"
#using "Company.Pins.Bank.Decryption.dll"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace System;
using namespace System::Runtime::InteropServices;
CPReSInterfaceApp theApp;
extern void UserInstruction1(
double* lpNumeric,
TCHAR* lpAlpha1, TCHAR* lpAlpha2)
{
//logic goes here
}
I assume here that all code resides in a single project (Company.Pins.Bank.Win32Console). If so you should move the <\iostream> and <\stdio.h> includes (and any other includes of headers that never/seldom change to stdafx.h:
and
and
If UserInstruction1 resides in a Dll that is used by the Company.Pins.Bank.Win32Console project:
Make sure you define in stdafx.h for the dll and console projects:
Open the properties for the DLL project, go to “Configuration Properties” -> “C/C++” -> “Preprocessor” and add to “Preprocessor Definitions” a preprocessor symbol (if you don’t have one). I.e. I’ll call it MY_DLL. Don’t forget to define it in all configurations…
Make sure you export the functions from the Dll
The cpp file for UInstruction remains the same as above…
EDIT: For completness…
Do not forget to add a reference to the Dll project to the Company.Pins.Bank.Win32Console project from the properties of the Company.Pins.Bank.Win32Console “Common Properties” -> “Framework and References”