Results 1 to 5 of 5

Thread: [RESOLVED] [2005] Referencing C++ DLL

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    Resolved [RESOLVED] [2005] Referencing C++ DLL

    I am having problems referencing a C++ DLL from my .Net App. Everything works fine onthe machine that I build the app but if I try to run the app on a different machine I get an error:

    Could not load file or assembly 'AClassLib'.

    I've simplified the app and DLL down to 2 functions. What am I missing?


    vb Code:
    1. Imports AClassLib
    2. Public Class Form1
    3.  
    4.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    5.         'Dim ACL As AClassLib.Class1 = New AClassLib.Class1
    6.         Dim ACL As New AClassLib.Class1
    7.         Dim a As Double
    8.         Dim b As Double
    9.         Dim c As Double
    10.  
    11.         a = TextBox1.Text
    12.         b = TextBox2.Text
    13.  
    14.         Try
    15.             c = ACL.AddEm(a, b)
    16.         Catch ex As Exception
    17.             MessageBox.Show("Button1_Click: " & ex.Message.ToString)
    18.         End Try
    19.  
    20.         lblAnswer.Text = c
    21.     End Sub
    22. End Class

    Code:
    #include "stdafx.h"
    
    #include "AClassLib.h"
    
    namespace AClassLib {
    
    	double Class1::AddEm(double A, double B)
    {
    	return A + B;
    }
    }

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    Re: [2005] Referencing C++ DLL

    It appears that you need to install a redistribution app to use the C++ DLL. The app is

    C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\vcredist_x86\vcredist_x86.exe

    Does anyone know why this application is required?

  3. #3
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005] Referencing C++ DLL

    you need to declare the function for the c++ dll. Just like declaring for API
    vb.net Code:
    1. Public Declare Function AddEm Lib "DLLName.dll" (ByVal A As Double, ByVal B As Double) As Double
    obviously replace DLLName.dll with the name of your dll.

    If you declare the function you can then call it from code. The c++ dll needs to be either in the application directory or the system32 directory
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    Re: [2005] Referencing C++ DLL

    you need to declare the function for the c++ dll. Just like declaring for API
    I tried that and it didn't work. I had to install the redistribtion application and everything is fine. I'mreading MSDN now about dll Manifests

    http://msdn2.microsoft.com/en-us/lib...42(vs.80).aspx

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    Re: [2005] Referencing C++ DLL

    Found the problem. Some of the other libraries that were being included in the main application was built as debug versus release. The dll could not resolve the debug functions and was crashing. Until we get release versions of the libraries we had to put debug versions of the CRT (msvcm80d,msvcp80d and msvcr80d) in the directory with our DLL.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width