0

I have my project file and Calculator01.dll file in same directory. When I'm trying to add a reference to Calculator.dll file message box appears and show

"A reference to 'E\IT131344............Calculato01.dll could not be added. Please make sure file is accessible and that it is a valid assembly or COM component."

I have already marked class functions with in CalDllWrapper class;

[DllImport("Calculator01.dll")]

Solutions I have found so far does not work for me. What can I do to resolve this problem? Please help me. thanks in advance

Skaranjit
  • 764
  • 9
  • 26
Pegasus
  • 88
  • 2
  • 9
  • 2
    Calculator01.dll is not a .Net dll? – Viru Feb 28 '16 at 10:08
  • You don't need to add a reference in order to use DllImport. – cbr Feb 28 '16 at 10:10
  • @Viru It is C-based DLL. C/C++ – Pegasus Feb 28 '16 at 10:13
  • @cubrr then how can i use DllImport? – Pegasus Feb 28 '16 at 10:13
  • right click on the dll file and go to properties, if in end of general tab, exist a button with unblock title, click that and retry. – vahid kargar Feb 28 '16 at 10:15
  • Possible duplicate of [Are there any better ways to copy a native dll to the bin folder?](http://stackoverflow.com/questions/3863419/are-there-any-better-ways-to-copy-a-native-dll-to-the-bin-folder) – Eugene Podskal Feb 28 '16 at 10:18
  • @Pegasus You just need to copy the imported DLL to the same directory as your executable (e.g. EugenePodskal's comment). See [this answer](http://stackoverflow.com/a/8861895/996081) for how the DllImportAttribute looks for the specified file. – cbr Feb 28 '16 at 10:40
  • @cubrr now it's working. thank you. DLL wasn't in the same directory. – Pegasus Feb 28 '16 at 14:27

1 Answers1

0

You can not add references to unmanaged DLLs. Only managed DLLs can be referenced. Unmanaged DLLs can only be used by using the DllImport attribute. Please note that the application needs to be able to access the DLL.

Thorsten Dittmar
  • 55,956
  • 8
  • 91
  • 139