By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,673 Members | 1,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,673 IT Pros & Developers. It's quick & easy.

dll files

P: n/a
I have a dll created by MS V C++ version 6 Class. The original files it was
based on were Borland and so this dll was created to use the Borland files
in a MS environment. However I am trying to access it in a .NET
application by adding it as a reference, and it keeps complaining that "a
reference to CDFSvrMS.dll could not be added. This is not a valid assembly
or com component."

I have tried to load up the MS VC++ version 6 project in .NET which seems to
automatically convert the project. However when the dll is re-compiled it
still does not work!

I have also tried to create a new dll from scratch, based on the cpp but it
complains "error C2872: 'IServiceProvider' : ambiguous symbol"

Any suggestions on how to get my dll working.
Nov 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Duncan,

Does the dll that you are using export c-style functions? If so, then
you can not add a reference to it. You can only add references to COM dlls
or to .NET assemblies. In order to call your functions from your program,
you would have to access them through the P/Invoke layer.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Duncan Winn" <te**@test1.co.uk> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
I have a dll created by MS V C++ version 6 Class. The original files it was based on were Borland and so this dll was created to use the Borland files
in a MS environment. However I am trying to access it in a .NET
application by adding it as a reference, and it keeps complaining that "a
reference to CDFSvrMS.dll could not be added. This is not a valid assembly or com component."

I have tried to load up the MS VC++ version 6 project in .NET which seems to automatically convert the project. However when the dll is re-compiled it
still does not work!

I have also tried to create a new dll from scratch, based on the cpp but it complains "error C2872: 'IServiceProvider' : ambiguous symbol"

Any suggestions on how to get my dll working.

Nov 13 '05 #2

P: n/a
Nicholas thanks...
Does the dll that you are using export c-style functions?
My dll has methods that return an object (if that is what you mean)?
In order to call your functions from your program, you would have to access them through the P/Invoke layer.


If that was what you meant then how do I use a P/Invoke layer?


Nov 13 '05 #3

P: n/a
Duncan,

In this case, you will have to create managed wrappers for the C++
classes which will expose those classes to .NET. You can not just add a
reference.

For a simple example of how to create a managed wrapper in C++ for .NET,
check out the section of the Managed Extensions for C++ Specification,
section 16.2, titled "__nogc Pointers in Managed Classes", located at (watch
for line wrap):

http://msdn.microsoft.com/library/de...sspec_16_2.asp

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Duncan Winn" <te**@test1.co.uk> wrote in message
news:eq**************@TK2MSFTNGP10.phx.gbl...
Does the dll that you are using export c-style functions?
does it have functions in it, like say user32.dll,
(SendMessage, etc, etc), or is it a COM server, which stores object types which you can instantiate (MSHTML, ADO, etc, etc).


I don't think it has c-Style functions in it. It basically contains a

suite of classes that have methods. The methods create instances of some of the
other classes in the dll and then return them???

Nov 13 '05 #4

P: n/a
Duncan,

If your DLL exports functions in the standard manner (STDCALL, for
example), then you can us the P/Invoke layer to access those functions.

--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Duncan Winn" <te**@test1.co.uk> wrote in message
news:um**************@TK2MSFTNGP11.phx.gbl...
Nicholas,

Sorry to mislead you, forget what I wrote before........ I have a dll file compiled in MS Visual C++ 6. It already provides a wrapper for the
classes that I am trying to access. The dll provides methods that do not
return anything they just manage data in the classes based on basic int and string input parameters. However, as stated before, I am having trouble
using the dll.

I am guessing that in this case I can just use P/Invoke as you originally
suggested??? Could I use a C++ dll in C#??? or would I need to re-code my
classes into C++????

Sorry and thanks...

Nov 13 '05 #5

P: n/a
Nicholas,

I have tried to use P/Invoke and it says it can't find my dll, I have tried
to specify the path etc,...here is my code....
#include "stdafx.h"

#using <mscorlib.dll>

#include <tchar.h>

//#include <D:\\provider\\CDFProv\\CPPTYest2\\CPPTYest2\\CDFS vrMS.dll>

using namespace System;

using namespace System::Runtime::InteropServices;

typedef void* HWND;
[DllImport("D:\\provider\\CDFProv\\CPPTYest2\\CPPTY est2\\CDFSvrMS.dll")]

extern "C" void diread(String* id, String* path);

void main(void) {

String* pText = L"Hello World!";

String* pCaption = L"D:\\FUMS\\cdf_db\\Historical
Fault View";

diread(pText, pCaption);

}
Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.