question

kavehrahimi-5744 avatar image
0 Votes"
kavehrahimi-5744 asked RLWA32-6355 answered

About *.lib *.h &*.dll

Hi ,I have three files CH341DLL.H ,CH341DLL.LIB & CH341DLL.DLL ,I want to add #include directive to it in my source code for CH341DLL.H and for CH341DLL.LIB add it to linker with -|CH341DLL argument and for CH341DLL.DLL I've been told to place it in system32 but my OS is windows 10 64 bit. I don't know how to do these works.
Please help me.
Thanks

vs-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RLWA32-6355 avatar image
2 Votes"
RLWA32-6355 answered

I've been told to place it in system32 but my OS is windows 10 64 bit. I don't know how to do these works.

It is bad practice to place user DLLs in the system folders. The best location for most user DLLs is in the folder that contains the application that uses them.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Castorix31 avatar image
1 Vote"
Castorix31 answered

Put the .h + .lib with your other sources
+
the .dll in the executable directory.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RLWA32-6355 avatar image
0 Votes"
RLWA32-6355 answered RLWA32-6355 commented

If you place the .lib file with your other source you need to instruct the linker how to find it.
One way is the include a statement like this in the source code -

     #pragma comment(lib, "CH341DLL.lib")

Another way is to set the "Additional Dependencies" property in the project's Linker->Input.

Go to the property sheet and click the down arrow (highlighted in red)
105424-linker-input.png
Then, if you placed your .lib file in the same folder as your sources (which should be the project folder containing the .vcxproj file) set the following
105441-linker-lib.png

Now the property page should look like this
105388-linkerdone.png

Accept the settings and close the property page.



linker-input.png (27.2 KiB)
linker-lib.png (10.3 KiB)
linkerdone.png (26.5 KiB)
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I am using VB.NET is that you said right for my situation too?

0 Votes 0 ·

I think you're a little confused by what you've been told. Header files and import libraries are not needed or used by managed code that uses functions exported from DLLs created using unmanaged code.

For VB.Net you should place CH341DLL.DLL in the same folder as your executable.

0 Votes 0 ·

I don't know how can I go to the property sheet. It seems that #pragma comment(lib, "CH341DLL.lib") statement only in C or C# is valid. What is the equvalent of it in VB.Net.

0 Votes 0 ·
Show more comments
kavehrahimi-5744 avatar image
0 Votes"
kavehrahimi-5744 answered RLWA32-6355 commented

I'd used declare statement in my code:
Private Declare Function CH341OpenDevice Lib "CH341DLL.DLL" (ByVal iIndex As Integer) As Integer
Private Declare Function CH341WriteI2C Lib "CH341DLL.DLL" (ByVal iindex As Integer, ByVal idevice As Integer, ByVal iaddr As Integer, ByVal ibyte As Integer) As Boolean
Private Declare Function CH341ReadI2C Lib "CH341DLL.DLL" (ByVal iindex As Integer, ByVal idevice As Integer, ByVal iaddr As Integer, ByVal obyte As Integer) As Integer
Private Declare Function CH341CloseDevice Lib "CH341DLL.DLL" (ByVal iIndex As Integer) As Integer
Private Declare Function CH341ResetDevice Lib "CH341DLL.DLL" (ByVal iIndex As Integer) As Integer
Sub main()
MsgBox("ok")
End Sub


 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
     Dim opening As Integer
     Dim closing As Integer
     Dim writing As Integer
     Dim reading As Integer
     Dim reseting As Integer
     reseting = CH341ResetDevice(0)
     opening = CH341OpenDevice(0)
     writing = CH341WriteI2C(0, 86, 22, 90)
     reading = CH341ReadI2C(0, 48, 91, 91)
     closing = CH341CloseDevice(0)
     MsgBox(reseting)
     MsgBox(writing)
     MsgBox(closing)
 End Sub

But when I run the code it returns value of CH341WriteI2C() wrong(for example zero).

· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

In your previous post at dll-exception.html I gave you substantial guidance but you never acknowledged that my prior suggestions, that you have now implemented, resolved your problem.


0 Votes 0 ·

Your prior suggestions resolved my problem but the problem here is not dll exception .it is the wrong value for return value for CH341WriteDevice()

0 Votes 0 ·

Then the courteous thing to do would be to accept my posts as the Answer to your prior question.

0 Votes 0 ·
Show more comments
RLWA32-6355 avatar image
1 Vote"
RLWA32-6355 answered

You are executing code from a third-party DLL. If the functions you are calling are not returning the expected results then either your expectations are incorrect or errors exist in the way you are using the functions.

In any case, you need to refer to the documentation of the functions exported by CH341DLL.DLL to resolve the specific issues that you are experiencing when using this third-party software.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.