Thread: DLLs trouble

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    48

    DLLs trouble

    Hi everyone. I've done a DLL with C, using Dev-C++ 4.9, and I want to use it from a code in VB.Net. Is this possible? or only DLLs created with C can be used from a C interface program?. Thanks in advance!.
    Regards.

  2. #2
    Registered User
    Join Date
    Nov 2007
    Posts
    48
    I got it done. But, another trouble now has appear. The thing is that I have a function in C getBytes, and when I call it from VB.Net, an error message appears, telling me this:
    "Object reference not set to an instance of an object".
    The weird thing is that if I call the function passing a 0 (zero) as argument it executes normally, but if i pass it any different value, I get that error mention above. I think may be it happens because of incompatible data types, but I don't know so.
    The signatures of the functions are:

    getBytes in C code:

    typedef unsigned long BITDATATYPE;

    void getBytes ( BITDATATYPE value );

    ---------------------------------------------
    In VB.Net I declare it with this signature:

    Private Shared Sub getBytes ( ByVal value As Long )
    End Sub

    I hope anyone can help me out on this.
    Regards folks.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    "Object reference not set to an instance of an object".

    This normally happens when the object you are attempting to access or alter does not exist. For instance if you have a class in C# and do not use new on it but then try to set a member variable or call one of its methods you will get this error.

    Code:
    namespace MyNamespace
    {
      partial class MyClass
      {
         private int m_Number;
    
         public int Number
         {
            get
            {
                return m_Number;
            }
            set 
            {
                m_Number=value;
            }
        }
         
      }
      
    
      partial class User
      {
         private MyClass AnObject;
         
         public User()
         {
    
            //Gives this error: "Object reference not set to an instance of an object".
            AnObject.Number = 10;
    
            //Proper way
            //AnObject = new MyClass();
            //AnObject.Number = 10;
    
         }
    
      }
    
    }
    
    
    }




    You could create an ATL COM object DLL out of your C code and then add the DLL to the references in your VB project. It's fairly simple but I think it goes far beyond the scope of this thread. Check google and the C# board. I just wrote a thread explaining how to get this done in C# and I'm sure it's much the same in VB.
    Last edited by VirtualAce; 11-28-2007 at 05:53 PM.

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    48
    thanks a lot bubba. I think I'll never understand why this error if I'm not creating any object here. Is it possible to create an ATL COM object from C?, I only have found information about C++.
    thanks again.

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You don't need to create one for C since you can just export the functions like any other normal 'C' DLL function.
    The COM object approach works well if you have C++ classes that have methods you wish to call. You cannot call these from C# or VB so you write a wrapper that does the call and returns the result to VB or C#. If you create a COM ATL object (the wizards make this a snap) and provide an interface to each of the functions you wish to wrap, theoretically this dummy COM object can be used by any code on the Windows platform.
    Last edited by VirtualAce; 11-29-2007 at 07:08 PM.

  6. #6
    Registered User
    Join Date
    Jul 2006
    Location
    US
    Posts
    14
    Bubba and all, apologize in advance, I'm facing a similar problem and I suspect that the solution might reside in your last reply. To trivialize my problem:
    I have two C++ dlls:
    1 - dlla contains a vector of objects, various classes and member functions. At runtime all is initialized and looks good.
    2 - dllb contains a fortran subroutine that is called by dlla at runtime.
    dlla loads the function pointer in dllb and executes the Fortran subroutine.
    dllb also makes some function calls into dlla.

    The problem is that the Fortran subroutine, in all the function calls made into dlla, seems to be returning with bogus/uninitialized memory (the vector of objects is now empty).

    I suspect that this might depend on the export of the functions in dlla or on multiple dll dependencies.
    So my question and request for help:
    when two dll are loaded and call functions between each other, what should I do?
    Is this scenario even possible?

    I'm a junior programmer, and I don't know much about software architecture, unfortunately!

    Thanks for any help.
    Ciao,
    Andrea.

  7. #7
    Registered User
    Join Date
    Jul 2006
    Location
    US
    Posts
    14
    Opps. typo: previous post should read I have two dlls, one C++ (dlla) and the other one Fortran dllb.
    Sorry for the confusion.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Some doubts on DLLs
    By BrownB in forum Windows Programming
    Replies: 1
    Last Post: 05-30-2007, 02:25 AM
  2. standart dlls
    By keeper in forum C++ Programming
    Replies: 3
    Last Post: 07-05-2006, 07:32 PM
  3. Can't load string from resource DLL's string table
    By s_k in forum Windows Programming
    Replies: 4
    Last Post: 07-15-2003, 06:43 AM
  4. question about DLL's and class functions
    By btq in forum Windows Programming
    Replies: 2
    Last Post: 02-25-2003, 06:08 AM
  5. DLLs <- sound files, and nesting.
    By sean in forum C++ Programming
    Replies: 2
    Last Post: 10-28-2002, 05:13 PM