Groups | Blog | Home
all groups > visual c > april 2004 >

visual c : Porting C++ to C++(.Net) Problem



sebastian.sosna NO[at]SPAM dregis.com
4/20/2004 4:34:06 AM
Hello NG !

Iam developing in C# so my cpp knowledge is limited.
Ive downloaded a C++ sample wich is doing some AD Job. U can get it
here :
http://support.microsoft.com/?id=302515

Ive tried to port into C++ (.Net) and ran into errors wich i have no
clue whats this is about. After compiling the linker is throwing those
errors :

//////////////////////////////////////////////////////////////////////////////
CppGetGuids error LNK2020: unresolved token (0600004D)
CppGetGuids.Class1::GetGuids
CppGetGuids error LNK2020: unresolved token (0A000017) atexit
CppGetGuids error LNK2020: unresolved token (0A000023)
??_7type_info@@6B@
CppGetGuids error LNK2020: unresolved token (0A000024)
_CxxThrowException
CppGetGuids error LNK2020: unresolved token (0A00002D) _CrtDbgReport
CppGetGuids error LNK2020: unresolved token (0A000033) free
CppGetGuids error LNK2020: unresolved token (0A000035) memset
CppGetGuids fatal error LNK1120: 7 unresolved externals
//////////////////////////////////////////////////////////////////////////////

What i have done so far:
-Started a Class Library ( .Net ) Project.
-Copied the Code from Main.cpp to CppGetGuids.cpp
-changed from int wmain(.....) to void GetGuids
-declared this Method in CppGetGuids.h
-Added in the Project Settings under Linker/Input Options the
ActiveDS.lib and Adsiid.lib.
-Got rid of (...wchar_t *argv[ ], wchar_t *envp[ ]) instead
ive declared (...String __gc* argv[ ],String __gc* envp[ ])

well now iam here with no idea what the Problem could be.
Hope somebody is willing to help me.
Thanks!
See below the full code so far:



CppGetGuids.cpp:

// This is the main DLL file.
#include "stdafx.h"
#include "CppGetGuids.h"
#include <String.h>
//
// The following code segment illustrates how to enumerate all of the
controlAccessRight objects
// whose appliesTo property matches the SchemaIDGUID of the given
SchemaClass object
//
#define _WIN32_WINNT 0x0500
#define UNICODE


void GetGuids( int argc,String __gc* argv[ ],String __gc* envp[ ] )
{
//
// NO error checking is performed. If a call fails, the code
// will end ungracefully. Do not use this code as an example of
how
// to properly handle COM errors.
//
// The program expects 1 argument, a CN for a schemaClass object.
// if the object name is missing, the code will terminate very
ungracefully.
// a sample command line would like:
//
// code_executable "cn=SchemaClass_Object_Common_Name"
//
// Assuming of course, that this code was compiled into an
executable called
// code_executable.exe
//
// Be sure to include:
// ActiveDS.lib
// Adsiid.lib
// on the Link tab of the project.
//
HRESULT hr = E_FAIL;
//
// Very Important for ADSI interfaces to work proper, must
initialize COM
//
CoInitialize(NULL);
//
// Check for the correct number of arguments
//
if( argc < 2 )
{
// PrintUsage();
// return E_FAIL;
}
//
// Need to bind to the RootDSE to locate the Schema and
Configuration Containers
//
CComPtr<IADs> oRootDSE;
VARIANT vData;
VariantInit(&vData);
CComBSTR bConfigurationNamingContext;
CComBSTR bSchemaNamingContext;
CComBSTR bDefaultNamingContext;
hr = ADsGetObject(
L"LDAP://deff0stv.adtwwz0sm.adtrootdom.net/RootDSE", IID_IADs, (LPVOID
*)&oRootDSE );
if( FAILED( hr ) )
{
printf("Error %d occured opening RootDSE object\nTerminating
Program\n");
// return E_FAIL;
}
hr = oRootDSE->Get(L"defaultNamingContext", &vData);
bDefaultNamingContext.AppendBSTR( vData.bstrVal );
VariantClear(&vData);
hr = oRootDSE->Get(L"SchemaNamingContext", &vData);
bSchemaNamingContext.AppendBSTR( vData.bstrVal);
VariantClear(&vData);
hr = oRootDSE->Get(L"ConfigurationNamingContext", &vData);
bConfigurationNamingContext.AppendBSTR(vData.bstrVal);
VariantClear(&vData );
oRootDSE.Release();
//
// Build the ControlAccessRight object path from the given
Extended Right
// passed as the first argument
//

const wchar_t __pin* p = PtrToStringChars(argv[1]);

CComBSTR bArg = p ;
CComBSTR bSchemaClassPath =
L"LDAP://deff0stv.adtwwz0sm.adtrootdom.net";
bSchemaClassPath.AppendBSTR( bArg );
bSchemaClassPath.Append( L",");
bSchemaClassPath.AppendBSTR( bSchemaNamingContext);
CComPtr <IADs> oSchemaClass;
hr = ADsGetObject( bSchemaClassPath.m_str, IID_IADs, (LPVOID *)
&oSchemaClass);
if( FAILED(hr) )
{
printf("Unable to open SchemaClass object :\n%S\nReceived error
%d\nTerminating Program\n",
bSchemaClassPath.m_str, hr);
//
// CleanUp and exit
//
oRootDSE.Release();
CoUninitialize();
// return hr;
}
//
// Retrieve the SchemaIDGUID of the SchemaClass object.
// The GUID must be converted into the form of an AppliesTo
// attribute GUID.
//
// Convert the GUID to a string, and strip the "{}"'s
//
oSchemaClass->Get(L"SchemaIDGUID", &vData );
oSchemaClass = NULL;
WCHAR wszGUID[40];
WCHAR *pwsz;
SAFEARRAY *pRefGUID;
SafeArrayAccessData( vData.parray, (VOID **)&pRefGUID);
StringFromGUID2( (REFGUID)*pRefGUID, wszGUID, 40 );
for( pwsz = wszGUID; *pwsz; pwsz++)
{
switch (*pwsz)
{
case '{':
break;
case '}':
*(pwsz-1) = (WCHAR)NULL;
break;
default:
*(pwsz-1) = *pwsz;
}
}
CComBSTR bAppliesToGUID = wszGUID;
//
// Time to do a bit of clean up. We are done with
// the safe array, the schemaIDGuid variant (vData) and
// the Schema Class object SO:
//
// Be sure to release the raw GUIDs safe array.
// Clear the variant AND
// Release the SchemaClass object
//
SafeArrayUnaccessData( pRefGUID );
VariantClear(&vData);
oSchemaClass.Release();
//
// Now, bind to the Extended Rights Container and retrieve an
IDirectorySearch
// interface to prepare for the LDAP search....
//
CComBSTR bExtendedRightBindString = L"LDAP://CN=Extended-Rights,";
bExtendedRightBindString.AppendBSTR( bConfigurationNamingContext);
CComPtr <IADs> oIADsExtendedRights;
hr = ADsGetObject( bExtendedRightBindString.m_str, IID_IADs,
(LPVOID *)&oIADsExtendedRights);
CComQIPtr <IDirectorySearch, &IID_IDirectorySearch> oSearch(
oIADsExtendedRights );
oIADsExtendedRights.Release();
//
// Build the LDAP query string that will look something like:
// LDAP Server : bDefaltNamingContext
// LDAP Query String:
(&(objectclass=controlAccessRight)(AppliesTo=MODIFIED_SCHEMAIDGUID))
// LDAP Properties to return: CN
// Search Properties: Paged Search
// Search Scope: Sub Tree ( from the schema container and beyond)
//
//
// Build the query string...
mccoyn
4/20/2004 5:16:02 AM
You GetGuids error is because in the header you have declared the function as part of a class, but in the source file you have definined the function as global. The definition should look like this
void CppGetGuids::Class1::GetGuids( int argc,String __gc* argv[ ],String __gc* envp[ ]

The remaining errors are problems with your include statements. I havn't gotten <String.h> and .Net to play nicely in the same file. You might want to consider dropping the #include <String.h> line. I think it would be easiest. I havn't used all of the headers you have. You may want to try to remove some and see if you can get away without them. You can also try including these headers before the #using <mscorlib.dll> statement or before any using namespace statements. As a final possibility you can create files which have no managed code and don't have any #using statements, that should have no trouble includeing these files. What is happening is the linker thinks these headers are managed code and is therefore looking for managed symbols. The symbols are contained in the CRT as unmanaged symbols, so they can not be found
AddThis Social Bookmark Button