dll files

D

Duncan Winn

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.
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
D

Duncan Winn

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?
 
N

Nicholas Paldino [.NET/C# MVP]

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/d...cmxspec/html/vcmanagedextensionsspec_16_2.asp

Hope this helps.
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
D

Duncan Winn

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\\CDFSvrMS.dll>

using namespace System;

using namespace System::Runtime::InteropServices;

typedef void* HWND;


[DllImport("D:\\provider\\CDFProv\\CPPTYest2\\CPPTYest2\\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);

}
 

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