locked
Unable to load dll

    Question

  • I have a dll that my form calls without issue but when I try to inherit the same form I get this error "Unable to load DLL '\FTD2XX.DLL': The specified module could not be found. (Exception from HRESULT: 0x8007007E)" . This happens if I try to view the inherited form in the editor. It actually works fine when I run the program but I would rather not have to add new controls dynamically. I've placed this dll in every folder I can think of to no avail.
    Dick Hutchings
    Tuesday, July 05, 2011 8:12 PM

Answers

  • I tried that and it didn't work so I tried just changing my original code from

    Dim file_name As String = Application.StartupPath
    file_name = String.Concat(file_name, "\bgnMain.jpg")

    to

    Dim file_name As String = Application.StartupPath
    file_name = String.Concat(file_name, ".\bgnMain.jpg")

    That worked.

    Thank you.


    Dick Hutchings
    Monday, July 18, 2011 2:09 PM

All replies

  • I have a dll that my form calls without issue but when I try to inherit the same form I get this error "Unable to load DLL '\FTD2XX.DLL': The specified module could not be found. (Exception from HRESULT: 0x8007007E)" . This happens if I try to view the inherited form in the editor. It actually works fine when I run the program but I would rather not have to add new controls dynamically. I've placed this dll in every folder I can think of to no avail.
    Dick Hutchings


    Hello DickHutchings,

     

    I think these threads can help http://social.msdn.microsoft.com/Forums/en/sqlce/thread/83970f13-3614-43b8-a454-6d527d9c0815

    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/6793785a-ec98-4453-a62b-f1a85195ec05

     

    Bye

     

     


    Carmelo La Monica  http://community.visual-basic.it/carmelolamonica/
    Tuesday, July 05, 2011 8:19 PM
  • Thanks but I didn't find any relevant information in either of those threads. My issue seems to be related to the inherited form and only in the editor.
    Dick Hutchings
    Tuesday, July 05, 2011 8:30 PM
  • Perhaps, there is only a problem of access modifier. Have you qualified your [dll-obkect] as Shared or Protected?

    Or are you loading the library at runtime?

    I think we need more info to underestand better


    please, mark this as answer if it is THE answer
    ----------------
    Diego Cattaruzza
    Microsoft MVP - Visual Basic: Development
    blog: http://community.visual-basic.it/Diego
    web site: http://www.visual-basic.it
    Wednesday, July 06, 2011 7:06 AM
  • I have a main form that uses this dll with out issue. The module that contains all the calls was written by someone at FTDCHIP and I've been using this for many years. The problem only appeared after I tried to inherit the main form to add some other controls as needed for other projects. The inherited form works fine in spite of this error while I'm editing. I just can't view the new form to add controls and have to do it dynamically which is more painful then it needs to be. Can I just turn off some error checking somewhere?


    Dick Hutchings
    Wednesday, July 06, 2011 2:53 PM
  • Hi Dick,

    What do you mean "The inherited form works fine in spite of this error while I'm editing"?

    Is it an error or a warning? Can you debug the application in VS ? As far as I know, when there is an compiling error in the project, the compiler will not rebuild the newer EXE file.

    As Diego said, how do you loading the library? By adding reference? Or by P/invoke? It is important to us to find the cause.

    I look forward you.

    Best regards,


    Mike Feng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, July 07, 2011 9:49 AM
    Moderator
  • In other words,the editor gives me an error only if I try to view the inherited form. I can edit and compile the code for the inherited form with no problem.

    I don't load the library as far as I can tell. I just make calls to the FTDI module and as I said this has been working fine until I decided to make an inherited form.

    If it might help, here are the declarations from the FTDI module.

     '===========================================================================================================================
      ' Declarations for device information functions in FTD2XX.dll:
      '===========================================================================================================================
      '"\FTD2XX.DLL"
      'Public file_name As String = Application.StartupPath
      'Public Const fn As String = String.Concat(file_name, "\FTD2XX.DLL")
      Public Declare Function FT_GetNumberOfDevices Lib "\FTD2XX.DLL" Alias "FT_ListDevices" (ByRef lngNumberOfDevices As Integer, ByVal pvArg2 As String, ByVal lngFlags As Integer) As Integer
      Public Declare Function FT_GetDeviceString Lib "\FTD2XX.DLL" Alias "FT_ListDevices" (ByVal lngDeviceIndex As Integer, ByVal lpszDeviceString As String, ByVal lngFlags As Integer) As Integer
      Public Declare Function FT_GetDeviceInfo Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByRef lngFT_Type As Integer, ByRef lngID As Integer, ByVal pucSerialNumber As String, ByVal pucDescription As String, ByRef pvDummy As Byte) As Integer
    
    
    
      '===========================================================================================================================
      ' Declarations for functions in FTD2XX.dll:
      '===========================================================================================================================
      Public Declare Function FT_OpenByIndex Lib "\FTD2XX.DLL" Alias "FT_Open" (ByVal intDeviceNumber As Integer, ByRef lngHandle As Integer) As Integer
      Public Declare Function FT_OpenBySerialNumber Lib "\FTD2XX.DLL" Alias "FT_OpenEx" (ByVal SerialNumber As String, ByVal lngFlags As Integer, ByRef lngHandle As Integer) As Integer
      Public Declare Function FT_OpenByDescription Lib "\FTD2XX.DLL" Alias "FT_OpenEx" (ByVal Description As String, ByVal lngFlags As Integer, ByRef lngHandle As Integer) As Integer
      Public Declare Function FT_Close Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer) As Integer
      Public Declare Function FT_Read_String Lib "\FTD2XX.DLL" Alias "FT_Read" (ByVal lngHandle As Integer, ByVal lpvBuffer As String, ByVal lngBufferSize As Integer, ByRef lngBytesReturned As Integer) As Integer
      Public Declare Function FT_Write_String Lib "\FTD2XX.DLL" Alias "FT_Write" (ByVal lngHandle As Integer, ByVal lpvBuffer As String, ByVal lngBufferSize As Integer, ByRef lngBytesWritten As Integer) As Integer
      Public Declare Function FT_Read_Bytes Lib "\FTD2XX.DLL" Alias "FT_Read" (ByVal lngHandle As Integer, ByRef lpvBuffer As Byte, ByVal lngBufferSize As Integer, ByRef lngBytesReturned As Integer) As Integer
      Public Declare Function FT_Write_Bytes Lib "\FTD2XX.DLL" Alias "FT_Write" (ByVal lngHandle As Integer, ByRef lpvBuffer As Byte, ByVal lngBufferSize As Integer, ByRef lngBytesWritten As Integer) As Integer
      Public Declare Function FT_SetBaudRate Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByVal lngBaudRate As Integer) As Integer
      Public Declare Function FT_SetDivisor Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByVal intDivisor As Integer) As Integer
      Public Declare Function FT_SetDataCharacteristics Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByVal byWordLength As Byte, ByVal byStopBits As Byte, ByVal byParity As Byte) As Integer
      Public Declare Function FT_SetFlowControl Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByVal intFlowControl As Integer, ByVal byXonChar As Byte, ByVal byXoffChar As Byte) As Integer
      Public Declare Function FT_ResetDevice Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer) As Integer
      Public Declare Function FT_SetDtr Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer) As Integer
      Public Declare Function FT_ClrDtr Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer) As Integer
      Public Declare Function FT_SetRts Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer) As Integer
      Public Declare Function FT_ClrRts Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer) As Integer
      Public Declare Function FT_GetModemStatus Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByRef lngModemStatus As Integer) As Integer
      Public Declare Function FT_SetChars Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByVal byEventChar As Byte, ByVal byEventCharEnabled As Byte, ByVal byErrorChar As Byte, ByVal byErrorCharEnabled As Byte) As Integer
      Public Declare Function FT_Purge Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByVal lngMask As Integer) As Integer
      Public Declare Function FT_SetTimeouts Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByVal lngReadTimeout As Integer, ByVal lngWriteTimeout As Integer) As Integer
      Public Declare Function FT_GetQueueStatus Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByRef lngRxBytes As Integer) As Integer
      Public Declare Function FT_GetLatencyTimer Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByRef ucTimer As Byte) As Integer
      Public Declare Function FT_SetLatencyTimer Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByVal ucTimer As Byte) As Integer
      Public Declare Function FT_GetBitMode Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByRef ucMode As Byte) As Integer
      Public Declare Function FT_SetBitMode Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByVal ucMask As Byte, ByVal ucEnable As Byte) As Integer
      Public Declare Function FT_SetUSBParameters Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByVal lngInTransferSize As Integer, ByVal lngOutTransferSize As Integer) As Integer
      Public Declare Function FT_SetBreakOn Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer) As Integer
      Public Declare Function FT_SetBreakOff Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer) As Integer
      Public Declare Function FT_GetStatus Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByRef lngamountInRxQueue As Integer, ByRef lngAmountInTxQueue As Integer, ByRef lngEventStatus As Integer) As Integer
    
      Public Declare Function FT_SetEventNotification Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByVal lngEventMask As Integer, ByVal lngEvent As Integer) As Integer
      ' event notification needs kernel32.dll functions to create events and threads
      ' Find kernel32 functions at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/dynamic_link_library_functions.asp
      Public Declare Function Sleep Lib "C:\windows\System32\kernel32.dll" (ByVal lngMilliseconds As Integer) As Integer
      '  Public Declare Function CreateEvent Lib "C:\windows\System32\kernel32.dll" Alias "CreateEventA" (ByVal lngEventAttributes As Integer, ByVal ucManualReset As Byte, ByVal ucInitialState As Byte, ByVal lpName As String) As Integer
      '  Public Declare Function WaitForSingleObject Lib "C:\windows\System32\kernel32.dll" (ByVal lngEventHandle As Integer, ByVal lngMilliseconds As Integer) As Integer
      '  Public Declare Function SetEvent Lib "C:\windows\System32\kernel32.dll" (ByVal lngEventHandle As Integer) As Integer
      '  Public Declare Function CreateThread Lib "C:\windows\System32\kernel32.dll" (ByVal lpThreadAttributes As Any, ByVal lngStackSize As Integer, ByVal lngStartAddress As Integer, ByVal lpParameter As Any, ByVal lngCreationFlags As Integer, ByVal lngThreadID As Integer) As Integer
      '  Public Declare Function TerminateThread Lib "C:\windows\System32\kernel32.dll" (ByVal lngThreadHandle As Integer, ByVal lngExitCode As Integer) As Integer
      '  Public Declare Function CloseHandle Lib "C:\windows\System32\kernel32.dll" (ByVal lngHandle As Integer) As Integer
    
    
      ' For returning strings from DLL calls using VB, see
      ' http://msdn.microsoft.com/library/default.asp?url=/library/en-us/modcore/html/deovrreturningstringsfromdllfunctions.asp
    
      '===========================================================================================================================
      'Declarations for the EEPROM-accessing functions in FTD2XX.dll:
      '===========================================================================================================================
      Public Declare Function FT_EraseEE Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer) As Integer
      Public Declare Function FT_EE_ReadEx Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByRef lpData As FT_PROGRAM_DATA, ByVal pucManufacturer As String, ByVal pucManufacturerID As String, ByVal pucDescription As String, ByVal pucSerialNumber As String) As Integer
      Public Declare Function FT_EE_ProgramEx Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByRef lpData As FT_PROGRAM_DATA, ByVal pucManufacturer As String, ByVal pucManufacturerID As String, ByVal pucDescription As String, ByVal pucSerialNumber As String) As Integer
      Public Declare Function FT_EE_UASize Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByRef lpdwSize As Integer) As Integer
      Public Declare Function FT_EE_UARead Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByRef pucData As Byte, ByVal dwDataLen As Integer, ByRef lpdwBytesRead As Integer) As Integer
      Public Declare Function FT_EE_UAWrite Lib "\FTD2XX.DLL" (ByVal lngHandle As Integer, ByRef pucData As Byte, ByVal dwDataLen As Integer) As Integer
    

     

    And the error.

    1 Error
    Why am I seeing this page?
    Unable to load DLL '\FTD2XX.DLL': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
       
     
    Instances of this error (1)
     
    1.   Show Call Stack
    at DLP_2232M.D2XX_Unit_NET.FT_Write_Bytes(Int32 lngHandle, Byte& lpvBuffer, Int32 lngBufferSize, Int32& lngBytesWritten)
    at DLP_2232M.Module1.WriteChA(Byte[] logic, Int32 bufferSize)
    at DLP_2232M.frmDLP_2232M.RadioButton1_CheckedChanged(Object sender, EventArgs e)
    at System.Windows.Forms.RadioButton.OnCheckedChanged(EventArgs e)
    at System.Windows.Forms.RadioButton.set_Checked(Boolean value)
    at DLP_2232M.frmDLP_2232M.InitializeComponent()
    at DLP_2232M.frmDLP_2232M..ctor()
     
    Help with this error
     
    Could not find an associated help topic for this error. Check Windows Forms Design-Time error list  
     
    Forum posts about this error
     
    Search the MSDN Forums for posts related to this error  

     


    Dick Hutchings
    Thursday, July 07, 2011 2:18 PM
  • As you can see, you are trying to write to the FTDI device in the design environment. More than likely, you don't want to do this. You are executing the code in the checkChanged event of an obtusely named radio button called RadioButton1, in the form constructor event. You probably want to do 2 things: make a 'flag' to indicate that you don't want control events to fire unless caused by a user input, and also check that the form is in the design time environment.


    Stephen J Whiteley
    Thursday, July 07, 2011 4:06 PM
  • As you can see, you are trying to write to the FTDI device in the design environment. More than likely, you don't want to do this. You are executing the code in the checkChanged event of an obtusely named radio button called RadioButton1, in the form constructor event. You probably want to do 2 things: make a 'flag' to indicate that you don't want control events to fire unless caused by a user input, and also check that the form is in the design time environment.


    Stephen J Whiteley


    Sorry, no I don't see. I wish I did. I have no idea why those things are happening nor how to do the 2 things you've told me to do. I hope you can help me with those steps.

    Thank you very much.


    Dick Hutchings
    Thursday, July 07, 2011 6:09 PM
  • Hi DickHutchings,

    From the error message, it seems that it cannot find the library. Generally, we only use the library name, without the symbol "\". So please remove it and try again.

    Best regards,


    Mike Feng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, July 08, 2011 4:45 AM
    Moderator
  • As you can see, you are trying to write to the FTDI device in the design environment. More than likely, you don't want to do this. You are executing the code in the checkChanged event of an obtusely named radio button called RadioButton1, in the form constructor event. You probably want to do 2 things: make a 'flag' to indicate that you don't want control events to fire unless caused by a user input, and also check that the form is in the design time environment.


    Stephen J Whiteley


    Sorry, no I don't see. I wish I did. I have no idea why those things are happening nor how to do the 2 things you've told me to do. I hope you can help me with those steps.

    Thank you very much.


    Dick Hutchings

    When you view the inherited form, you are executing code in that form. In your case, you are executing the CheckedChanged event code. Do you need this code to execute in the development environment? Do you want to try to WriteBytes to your device?

    To prevent execution of this code, you will need to put in a flag to indicate when you want this code to execute: that is, a boolean variable that you will set true when you are actually executing the application. You can also look at the forms DesignTime property: if it is true, then you are in the IDE, and you can prevent the code from executing (there are some circumstances when this may return false, so an additional check will need to be made).

    The reason it cannot find the DLL is that it is not in the correct location relating to the IDE execution (which is why it can be found when you execute the application). Your best bet to resolve such issues (particularly in the future) is encapsulate all your invocation calls to a DLL in a class which can perform all appropriate checks, rather than calling these methods directly from a UI.


    Stephen J Whiteley
    Friday, July 08, 2011 1:37 PM
  • Hi DickHutchings,

    From the error message, it seems that it cannot find the library. Generally, we only use the library name, without the symbol "\". So please remove it and try again.

    Best regards,


    Mike Feng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Mike

    That solved the dll issue but now I have another file location issue with a background image. Here's the new error.

    1 Error
    Why am I seeing this page?
    C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\bgnMain.jpg
       
     
    Instances of this error (1)
     
    1.   Hide Call Stack
    at System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement)
    at System.Drawing.Image.FromFile(String filename)
    at DLP_2232M.Module1.SetFormStyle(Form aForm) in C:\Documents and Settings\fc8r7c\My Documents\Visual Studio 2010\Projects\Copy of DLP2232M\DLP-2232M\Module1.vb:line 126
    at DLP_2232M.frmDLP_2232M.SPI_Load(Object eventSender, EventArgs eventArgs) in C:\Documents and Settings\fc8r7c\My Documents\Visual Studio 2010\Projects\Copy of DLP2232M\DLP-2232M\frmDLP_2232M.vb:line 1616
    at System.Windows.Forms.Form.OnLoad(EventArgs e)
    at System.Windows.Forms.Form.OnCreateControl()
    at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
    at System.Windows.Forms.Control.CreateControl()
    at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
    at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
    at System.Windows.Forms.Control.set_Visible(Boolean value)
    at System.Windows.Forms.Design.DesignerFrame.Initialize(Control view)
    at System.Windows.Forms.Design.DocumentDesigner.Initialize(IComponent component)
    at System.Windows.Forms.Design.FormDocumentDesigner.Initialize(IComponent component)
    at System.ComponentModel.Design.DesignerHost.AddToContainerPostProcess(IComponent component, String name, IContainer containerToAddTo)
    at System.ComponentModel.Design.DesignerHost.PerformAdd(IComponent component, String name)
    at System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.CreateComponent(Type componentType, String name)
    at System.ComponentModel.Design.Serialization.DesignerSerializationManager.CreateInstance(Type type, ICollection arguments, String name, Boolean addToContainer)
    at System.ComponentModel.Design.Serialization.DesignerSerializationManager.System.ComponentModel.Design.Serialization.IDesignerSerializationManager.CreateInstance(Type type, ICollection arguments, String name, Boolean addToContainer)
    at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
    at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
    at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
    at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)

     

    Here's the actual code. Again it runs fine until I try to view the inherited form.

     Dim file_name As String = Application.StartupPath
        file_name = String.Concat(file_name, "\bgnMain.jpg")
        aForm.BackgroundImage = Image.FromFile(file_name)

     


    Dick Hutchings
    Friday, July 08, 2011 2:00 PM
  • Steve

    I can't find the DesignTime property to change it. There's no such thing in the property list. Looks like I fixed the dll problem just by removing the "\" per Mikes suggestion but I'm having the same problem with a jpg that seems to get loaded at DesignTime instead of runtime. I don't know how to write this block of code.

     If ????? then
          Dim file_name As String = Application.StartupPath
          file_name = String.Concat(file_name, "\bgnMain.jpg")
          aForm.BackgroundImage = Image.FromFile(file_name)
        End If

     

    Dick Hutchings
    Friday, July 08, 2011 2:14 PM
  • After commenting out this code

     Dim file_name As String = Application.StartupPath
          file_name = String.Concat(file_name, "\bgnMain.jpg")
          aForm.BackgroundImage = Image.FromFile(file_name)

    Everything works perfectly. I can now edit the inherited form in the IDE. I would still like to be able to run that block of code though to give all my forms the same background image.


    Dick Hutchings
    Friday, July 08, 2011 2:38 PM
  • Hi DickHutchings,

    please comment the two line:

    Dim file_name As String = Application.StartupPath
    file_name = String.Concat(file_name, "\bgnMain.jpg")


    and try this code:

     aForm.BackgroundImage = Image.FromFile(".\bgnMain.jpg")

     I hope this will be helpful.

    Best regards,


    Mike Feng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, July 11, 2011 5:23 AM
    Moderator
  • Dick,

    Be aware that by using more forms you are not creating a kind of multitask program. A form is just a window somewhere in memory. The application framework connects your program to the mainform, if you use ShowDialog the next form becomes modale and gets the command. If you use MDI, than the same happens but than inside a container everytime you switch. However if you use Show than you should not have any code in that next form, it is fine for showing a splash screen with a timmer in it.

     


    Success
    Cor
    Monday, July 11, 2011 6:59 AM
  • I tried that and it didn't work so I tried just changing my original code from

    Dim file_name As String = Application.StartupPath
    file_name = String.Concat(file_name, "\bgnMain.jpg")

    to

    Dim file_name As String = Application.StartupPath
    file_name = String.Concat(file_name, ".\bgnMain.jpg")

    That worked.

    Thank you.


    Dick Hutchings
    Monday, July 18, 2011 2:09 PM
  • Cor

    The whole reason Im using multiple forms is because I have many projects that use the main set of controls but they all need their own additional set of controls and the form was getting too cluttered. When I used the panels for the different controls by showing and hiding them, the form had too many controls and took forever for the editor to refresh the form. This is why I've gone to multiple forms. I think the inherited forms is a much better way to go for future projects. I just need to make it work, which I have now thanks to all the help I got here.


    Dick Hutchings
    Monday, July 18, 2011 2:20 PM