Compiling and including a DLL

Hi there. I'd like to write a class and compile it to a dll so I can include it in a number of different applications. However, I am having trouble getting any dll that I've compiled to add successfully to my test application that imports the dll.

To test, I did the following:
- Started a new project in C++, and under 'Smart Device' chose 'MFC Smart Device DLL' as my chosen template.
- Then clicked "Next" through to select the Windows Mobile 5.0 Pocket PC SDK to be added to my project.
- At 'Application Settings' I left this as the default selected to 'Regular DLL with MFC statically linked'. I don't really know what this means and how it might affect my application.
- Hit finish, and from the new project I build the DLL (F6) and it completely successfully.

I go back to my test application, which is a C# Windows Mobile 5.0 Pocket PC application, and go to "Add a Reference", browse to the newly created dll from above, and select it. I then get an error message:
"A reference to 'mydll.dll' could not be added"
With no further information.

So I guess the question is, can a dll from C++ source code not be included in a C# application Or, is there something very obvious that I'm doing wrong here

Thank you very much for any suggestions, your time and help.
-Dana


Answer this question

Compiling and including a DLL

  • JedG

    Thanks for your reply; that makes a lot of sense and was not something I thought of, as I am new to writing MS applications. Again, much thanks!
  • Colin F

    Hi Dana,

    some things..

    as far as I know you can't add dll that has written as MFC to a .NET project, add reference is used to add dll written in .NET framework.

    the best way I thinks is to do a dll import in the c# project (to your dll) and then use it like any dll import..

    example:

    [DllImport("coredll.dll",)]

    public static extern bool sndPlaySoundW(String path, IntPtr hmod, uint fdwSound);

    hope it was helping :)

    Oren.


  • Compiling and including a DLL