question

AlexB-7522 avatar image
0 Votes"
AlexB-7522 asked YujianYao-MSFT commented

Can not create object of DirectorySearcher class with Visual C++ MFC with project reference of System.DirectoryServices.dll

System.DirectoryServices.dll file has been added successfully to Visual C++ MFC .NET project through References in Solution Explorer.
Microsoft Development Environment 2003 Version 7.1.3088.
Microsoft .Net Framework 1.1 Version 1.1.4322

using namespace System::DirectoryServices;//line 1268
void CClassName::MethodName(){
...
DirectorySearcher* directorySearcher = new
DirectorySearcher();//line 1701
directorySearcher->ClientTimeout = 60000;//line 1702
...
}

file.cpp(1701): error C2061: syntax error : identifier 'DirectorySearcher'
file.cpp(1701): error C2065: 'directorySearcher' : undeclared identifier
file.cpp(1701): error C2065: 'DirectorySearcher' : undeclared identifier
file.cpp(1702): error C2227: left of '->ClientTimeout' must point to class/struct/union
type is ''unknown-type''
file.cpp(1268): error C2653: 'System' : is not a class or namespace name
file.cpp(1268): error C2871: 'DirectoryServices' : a namespace with this name does not exist
file.cpp(1702): error C3861: 'directorySearcher': identifier not found, even with argument-dependent lookup

By this way I need to set Request Timeout for SOAP WebService

c++
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


According to the error at line 1268, maybe the DLL was not added correctly, or the project does not include the Common Language RunTime option (/clr).

The code seems to work in Visual Studio 2022 with .NET Framework 4.8 and some adjustments.


0 Votes 0 ·

Hi @AlexB-7522,

I recommend that you read this document and refer to the settings there. You could also try with newer vs and .net framework.


0 Votes 0 ·

Hi @AlexB-7522,

May I know if you have got any update?

0 Votes 0 ·
AlexB-7522 avatar image
0 Votes"
AlexB-7522 answered Viorel-1 commented

Thank you,
It is Visual C++ MFC software. I understand that MFC project can not come
together with Common Language RunTime option (/clr).

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AlexB-7522 avatar image
0 Votes"
AlexB-7522 answered RLWA32-6355 edited

I have performed what is explained in the article.
Still I get the error: file.cpp: fatal error C1190: managed targeted code requires '#using <mscorlib.dll>' and '/clr' option
/clr option in my Visual Studio can be set only by the level of code method and i did it. Compile as mannaged: Assembly Support (/clr).


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Microsoft Development Environment 2003 Version 7.1.3088.
Microsoft .Net Framework 1.1 Version 1.1.4322


You wrote that you were using these for development. They are ancient.

Can you use current versions of Visual Studio, VC++ and the .Net Framework?

0 Votes 0 ·
AlexB-7522 avatar image
0 Votes"
AlexB-7522 answered AlexB-7522 edited

First of all thank you for your help.
You was right - the code I published is only for managed /clr environment.
I have tried today again to create /clr environment with minimum changes in project properties.
I has began from change: Compile as Managed - Assembly Supprt(/clr) and continued until I did not get any negative comment.
And has added some additions according to example of similar code structure from online book(From this book I got main explaination about code to use for setting timeot).
It passes compilation. The result will be known tommorrow when we will perform the test.
I have tried to perform conversion to modern environment but there were a huge number of errors after it.
Our software is very big and complicated

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.