none
Problem in accessing functions in a DLL

    Question

  • Hi All,

    I have a strange problem...
    I have VS2005 on WinXP and am making a Windows Project.When I ran the project I got an error
    "Unable to find an entry point name "foo" in dll "foo.dll".
    However the dll is present in Windows\System32 directory and the Path also references the directory
    So I added a reference to the dll in the System32 folder but it showed an error that "A reference to ....dll cannot

    be added.Please make sure that the file is accessible, and that it is a valid assembly or COM component".
    Next I ran "tlbimp foo.dll" from VS2005 command prompt.I got an error "The input file 'foo.dll' is not a valid type

    library.So I ran "regsvr32 foo.dll" and I got an error "foo.dll was loaded, but the DLLRegisterServer entry point

    was not found.This file cannot be registered".All I want is to make use of the functions in foo.dll.Any ideas will

    be appreciated.

    Saturday, October 07, 2006 3:01 PM

All replies

  • "Unable to find an entry point name "foo" in dll "foo.dll"."

    This means that DLL found wherever it was. (Are you telling which function to call?)

    "However the dll is present in Windows\System32 directory and the Path also references the directory
    So I added a reference to the dll in the System32 folder but it showed an error that "A reference to ....dll cannot be added.Please make sure that the file is accessible, and that it is a valid assembly or COM component".

    Refrence can be added to COM and .Net Dlls only, I think you foo.dll a native dll but not COM or .Net dll that's why your are getting this error while adding reference.


    "Next I ran "tlbimp foo.dll" from VS2005 command prompt.I got an error "The input file 'foo.dll' is not a valid type library.So I ran "regsvr32 foo.dll" and I got an error "foo.dll was loaded, but the DLLRegisterServer entry point was not found.This file cannot be registered".

    regsvr32 is also valid only from registring COM dlls and ActiveX Controls (with .ocx Extension).

    "All I want is to make use of the functions in foo.dll.Any ideas will be appreciated."

    Make sure these things:

    1. Your dll is not a COM or .Net dll.
    2. If above point is true then the only way left is DllImport attribute (P/Invoke way) and define functions to whom you want to call.
    3. Call them from your code.

    I hope this will work ;-)

    Best Regards,

     

    Saturday, October 07, 2006 5:39 PM
  • I got the answer...but with a problem again...
    It seems that another application(let me call that application as AppA) had overwritten the foo.dll in Windows\System32 directory.So when I ran my Windows project,it was calling a function foo which was not present in the current version of foo.dll.
    So I installed the application(let me call that as AppB) which would give me the correct version of foo.dll.Now since the correct version of foo.dll is present in  Windows\System32 directory, the Windows project works fine.But now AppA does not work as it depends on the older version of foo.dll.
    Now what on earth can I do to make both AppA(which depends on older foo.dll) and my Windows project(which depends of newer foo.dll supplied by AppB) to work together?

    Sunday, October 08, 2006 5:44 AM
  • This is commonly known as "DLL Hell". .NET fixed this problem using the GAC, but for non-.NET dll's, the only way around it is to manually copy the dll to another location where it can be loaded by the application that needs it. For example, since you have AppB currently installed, copy the dll from system32 to the directory where AppB is located. Then re-install AppA.
    Monday, October 09, 2006 2:09 AM
    Moderator
  • Hi

    Thanks for the reply.Here is what I did...
    1)I moved the new foo.dll needed by AppB from system32 to the bin\Debug folder
    2)Without re-installing AppA, I ran AppB(Windows Project),but it was still not working as it was refering to the dll from the System32 folder.
    Let me clarify a few things here...
    AppA is an an installation package which refers to the older foo.dll.
    The new foo.dll came with another installation package which contains several new dll's which are needed by
    AppB(my Windows project).Let me call one among the several dll's as 'x.dll'.I can add a reference to x.dll
    in AppB but in turn it looks for the new foo.dll in System32 folder.So even if I move the foo.dll from System32
    to the bin folder,the AppB does not work as it was still refering to the dll from the System32 folder.
    I don't know if I am doing anything wrong.But I am pretty bugged up by the DLL hell.I still have no solution...

     

    Monday, October 09, 2006 4:40 AM
  • Are you referencing x.dll directly from your project? If so, you should change the reference to the local directory, instead of in system32. If this doesn't work, I would suggest intalling AppA and moving x.dll into its application directory, and then reinstalling the package with the version of x.dll that you need.
    Tuesday, October 10, 2006 4:21 AM
    Moderator
  • Nope, none of it worked.

    Ok,I need to know how to store a byte array of image type "raw" into sql "image"  field.The catch is that the image is not present on the hard drive but is obtained from an encoded file as an array of bytes.

    i.e. byte[] img=EncodedFile("raw");

         Now 'img' needs to be saved into 'image' field without getting written into the hard disk.

     

    Tuesday, October 10, 2006 7:46 AM