Using unmanaged C++ in C++.NET

P

praveenkojha

Hi,

I am novice in C++ and am more of a C# guy. I have a third party C++
code which I want to create and use as a managed assembly. I have
created a .NET win32 application and have copied this C++ code here and
made changes according to my needs. However I am always getting this
linker error when compiling. I looked a lot n the web and followed all
instructions so far of adding msvcrt.lib, glu32.lib, opengl32.lib to
the project dependencies. The error description is below. Any help is
highly appreciated.

Linking...
TestProjDll.obj : error LNK2001: unresolved external symbol "void
__stdcall liEndDocument(void *,struct LanguageIDListT *,long *)"
(?liEndDocument@@$$FYGXPAXPAULanguageIDListT@@PAJ@Z)
TestProjDll.obj : error LNK2001: unresolved external symbol "void
__stdcall liAnalyzeDocumentText(void *,char *,unsigned int,long *)"
(?liAnalyzeDocumentText@@$$FYGXPAXPADIPAJ@Z)
TestProjDll.obj : error LNK2001: unresolved external symbol "void
__stdcall liStartDocument(void *,long *)"
(?liStartDocument@@$$FYGXPAXPAJ@Z)
TestProjDll.obj : error LNK2001: unresolved external symbol "void
__stdcall liSetCharacterSetFlags(void *,enum BooleanT,enum
BooleanT,enum BooleanT,enum BooleanT,enum BooleanT,long *)"
(?liSetCharacterSetFlags@@$$FYGXPAXW4BooleanT@@1111PAJ@Z)
TestProjDll.obj : error LNK2001: unresolved external symbol "void
__stdcall liOpenLanguage(void *,char *,char *,int *,long *)"
(?liOpenLanguage@@$$FYGXPAXPAD1PAHPAJ@Z)
TestProjDll.obj : error LNK2001: unresolved external symbol "void
__stdcall liDeleteLanguageIdentifier(void *,long *)"
(?liDeleteLanguageIdentifier@@$$FYGXPAXPAJ@Z)
TestProjDll.obj : error LNK2001: unresolved external symbol "void *
__stdcall liCreateLanguageIdentifier(unsigned long,unsigned long,long
*)" (?liCreateLanguageIdentifier@@$$FYGPAXKKPAJ@Z)
D:\Praveen\Work\LanguageIdentifiertest\TestProj\TestProjDll\Debug\TestProjDll.dll
: fatal error LNK1120: 7 unresolved externals



I am using the following code in my header file:

// TestProjDll.h

#pragma once

using namespace System;
#include "stdlib.h"

#include "string.h"
#include "stdio.h"

namespace TestProjDll
{

#ifndef __LANGUAGE_ID_
#define __LANGUAGE_ID_

#include <stdlib.h>

//#define __LEXTEK_MACINTOSH__
//#define __LEXTEK_SOLARIS__
//#define __LEXTEK_LINUX32__
//#define __LEXTEK_BEOS__
#define __LEXTEK_WINDOWS_DLL__
#define __LEXTEK_MICROSOFT__
//#define __LEXTEK_BORLAND__



#ifdef __LEXTEK_MACINTOSH__
# define WinStuff
# define FuncType
#endif

#ifdef __LEXTEK_BORLAND__
# ifdef __LEXTEK_WINDOWS_DLL__
# define FuncType __export __stdcall
# endif
# define WinStuff
#endif

#ifdef __LEXTEK_MICROSOFT__
# define FuncType __stdcall
# ifdef __LEXTEK_WINDOWS_DLL__
# define WinStuff __declspec(dllexport)
# endif
#endif

#ifdef __LEXTEK_SOLARIS__
# define FuncType
# define WinStuff
#endif

#ifdef __LEXTEK_LINUX32__
# define FuncType
# define WinStuff
#endif


#ifdef __LEXTEK_BEOS__
# define FuncType
# define WinStuff
#endif

typedef void * LextekLanguageIdentiferT;
typedef unsigned long ULongT;
typedef long int StatusCodeT;

#ifndef __BOOLEANT__
#define __BOOLEANT__
typedef enum {
BooleanTrue = 1,
BooleanFalse = 0
} BooleanT;
#endif


#ifndef __LEXTEK_STATUS_CODE__
#define __LEXTEK_STATUS_CODE__
typedef long StatusCodeT;
#endif




#ifndef __LEXTEK_STATUS_CODES__
#define __LEXTEK_STATUS_CODES__

// Note, the error code values have been brought in line with the
error
// code values from other Lextek products. This is the reason why the
// values are not sequential.

const long eNoError = 0; // NoError;
const long eNoMemory = -1; // Not enough memory
const long eReading = -3; // Error reading from file
const long eWriting = -4; // Error writing to file
const long eSeeking = -5; // We were not able to seek
where we wanted
const long eFileNotFound = -6; // Not able to find the file
const long eOpeningFile = -11;// Can't open the file specified
const long eGeneralError = -37; // Beats me what the error is
const long eLibraryTimedOut = -39; // This library has timed out.
Contact Support ([email protected])
const long eInvalidPasscode = -42; // An invalid license passcode
was entered. Recheck passcode or contact Lextek International
(http://www.lextek.com) for a valid passcode.

#endif


#define UNICODE_FLAG_BIG_ENDIAN (0x00000001)
#define UNICODE_FLAG_LITTLE_ENDIAN (0x00000002)
#define UNICODE_FLAG_UTF8 (0x00000004)
#define UNICODE_FLAG_UTF7 (0x00000008) // Not supported.
#define UNICODE_FLAG_UTF75 (0x00000010) // Not supported.

struct LanguageIdentificationT {
char LanguageIDString[80];
int LanguageIDNum;
unsigned int UnicodeFlags;
float Weight;
};

struct LanguageIDListT {
BooleanT LanguageFound;
LanguageIdentificationT Language[4];
int LanguageIDCount;
};

WinStuff LextekLanguageIdentiferT FuncType
liCreateLanguageIdentifier(ULongT Passcode1, ULongT Passcode2,
StatusCodeT *Status);
WinStuff void FuncType
liDeleteLanguageIdentifier(LextekLanguageIdentiferT LanguageIdentifer,
StatusCodeT *Status);
WinStuff void FuncType liSetCharacterSetFlags(LextekLanguageIdentiferT
LanguageIdentifer, BooleanT TestUnicodeBigEndianFlag, BooleanT
TestUnicodeLittleEndianFlag, BooleanT TestUTF8Flag, BooleanT
Check8BitCharSets, BooleanT CheckMultiByteCharSets, StatusCodeT
*Status);

WinStuff void FuncType liOpenLanguage(LextekLanguageIdentiferT
LanguageIdentifer, char *FileName, char *LangIDString, int *LangIDNum,
StatusCodeT *Status);
WinStuff void FuncType liCloseLanguage(LextekLanguageIdentiferT
LanguageIdentifer, char *LanguageName, int LangIDNum, StatusCodeT
*Status);

WinStuff void FuncType liStartDocument(LextekLanguageIdentiferT
LanguageIdentifer, StatusCodeT *Status);
//WinStuff void FuncType
liAnalyzeDocumentText(LextekLanguageIdentiferT LanguageIdentifer, char
*Text, size_t NumCharacters, size_t CharacterSize, StatusCodeT
*Status);
WinStuff void FuncType liAnalyzeDocumentText(LextekLanguageIdentiferT
LanguageIdentifer, char *Text, size_t NumBytes, StatusCodeT *Status);
WinStuff void FuncType liEndDocument(LextekLanguageIdentiferT
LanguageIdentifer, LanguageIDListT* IDList, StatusCodeT *Status);


#endif



public __gc class Class1
{
// TODO: Add your methods for this class here.
int identLG(char *SampleText)
{
StatusCodeT Status = eNoError;
LextekLanguageIdentiferT LanguageIdentifier = NULL;
LanguageIDListT LanguageIDList;
char LanguageIDString[80];
int LanguageIDNum;

LanguageIdentifier = liCreateLanguageIdentifier(0x7F8BC654,
0x54A43ADD, &Status);
if(LanguageIdentifier == NULL) {
return -1;
}

if(Status < 0) {
liDeleteLanguageIdentifier(LanguageIdentifier, &Status);
return -1;
}

liOpenLanguage(LanguageIdentifier,
"language_modules\\english_8bit.lid", LanguageIDString, &LanguageIDNum,
&Status);
liOpenLanguage(LanguageIdentifier,
"language_modules\\french_8bit.lid", LanguageIDString, &LanguageIDNum,
&Status);

liSetCharacterSetFlags(LanguageIdentifier,
BooleanFalse, // Test For Unicode Big Endian Text Flag
BooleanFalse, // Test For Unicode Little Endian Text Flag
BooleanFalse, // Test For Unicode UTF-8 Text Flag
BooleanTrue, // Test 8 Bit Character Sets.
BooleanFalse, // Test Multibyte Character Sets.
&Status);

liStartDocument(LanguageIdentifier, &Status);
if(Status < 0) {
liDeleteLanguageIdentifier(LanguageIdentifier, &Status);
return -1;
}

liAnalyzeDocumentText(LanguageIdentifier, (char *) SampleText,
strlen(SampleText), &Status);
if(Status < 0) {
liDeleteLanguageIdentifier(LanguageIdentifier, &Status);
return -1;
}

liEndDocument(LanguageIdentifier, &LanguageIDList, &Status);
if(Status < 0) {
liDeleteLanguageIdentifier(LanguageIdentifier, &Status);
return -1;
}


//return LanguageIDNum;
return 1;
}
};

}


Thanks
Praveen Ojha
 
A

Arnaud Debaene

Hi,

I am novice in C++ and am more of a C# guy. I have a third party C++
code which I want to create and use as a managed assembly. I have
created a .NET win32 application and have copied this C++ code here
and
made changes according to my needs. However I am always getting this
linker error when compiling. I looked a lot n the web and followed all
instructions so far of adding msvcrt.lib, glu32.lib, opengl32.lib to
the project dependencies. The error description is below. Any help is
highly appreciated.

Linking...
TestProjDll.obj : error LNK2001: unresolved external symbol "void
__stdcall liEndDocument(void *,struct LanguageIDListT *,long *)"
(?liEndDocument@@$$FYGXPAXPAULanguageIDListT@@PAJ@Z)
TestProjDll.obj : error LNK2001: unresolved external symbol "void
__stdcall liAnalyzeDocumentText(void *,char *,unsigned int,long *)"
(?liAnalyzeDocumentText@@$$FYGXPAXPADIPAJ@Z)
TestProjDll.obj : error LNK2001: unresolved external symbol "void
__stdcall liStartDocument(void *,long *)"
(?liStartDocument@@$$FYGXPAXPAJ@Z)
TestProjDll.obj : error LNK2001: unresolved external symbol "void
__stdcall liSetCharacterSetFlags(void *,enum BooleanT,enum
BooleanT,enum BooleanT,enum BooleanT,enum BooleanT,long *)"
(?liSetCharacterSetFlags@@$$FYGXPAXW4BooleanT@@1111PAJ@Z)
TestProjDll.obj : error LNK2001: unresolved external symbol "void
__stdcall liOpenLanguage(void *,char *,char *,int *,long *)"
(?liOpenLanguage@@$$FYGXPAXPAD1PAHPAJ@Z)
TestProjDll.obj : error LNK2001: unresolved external symbol "void
__stdcall liDeleteLanguageIdentifier(void *,long *)"
(?liDeleteLanguageIdentifier@@$$FYGXPAXPAJ@Z)
TestProjDll.obj : error LNK2001: unresolved external symbol "void *
__stdcall liCreateLanguageIdentifier(unsigned long,unsigned long,long
*)" (?liCreateLanguageIdentifier@@$$FYGPAXKKPAJ@Z)
D:\Praveen\Work\LanguageIdentifiertest\TestProj\TestProjDll\Debug\TestProjDll.dll

You miss the source code file (or library) that defines the functions
liEndDocument, liAnalyzeDocument, etc... Isnt't that part of the Latex
library you seems to use?

Arnaud
MVP - VC
 
P

praveenkojha

Hi,

Thanx for your response. It worked for me. I had to addd a reference to
the lib file of the external functionas and was not able to locate
where in project properties I could do that. Have got it resolved now.
Thanks for your help.

-Praveen Ojha
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top