|
Hi, Christian
The source code is not at hand now. Later I send to you to check. I try to call functions of unmanaged VC++ DLL. it compiled no error, but can't get the handle ( value is &H0). Can you give me some information or another useful articles / link. Thank you very much!
James
|
|
|
|
|
James8888 wrote:
I try to call functions of unmanaged VC++ DLL.
How did you link to the dll ?
Here[^] is the first hit I got from google.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I call it like this
Imports System.Runtime.InteropServices
Public Class Win32
Declare Auto Function MessageBox Lib "user32.dll" _
(ByVal hWnd As Integer, _
ByVal txt As String, ByVal caption As String, _
ByVal Typ As Integer) As Integer
End Class
But don't know what is difference between above and below
Imports System.Runtime.InteropServices
Public Class Win32
<dllimport ("user32.dll",="" charset="" :="CharSet.Auto)"> _
Public Shared Function MessageBox (ByVal hWnd As Integer, _
ByVal txt As String, ByVal caption As String, _
ByVal Typ As Integer) As Integer
End Function
End Class
What is CharSet?
thanks, James
|
|
|
|
|
James8888 wrote:
Public Shared Function MessageBox (ByVal hWnd As Integer, _
ByVal txt As String, ByVal caption As String, _
ByVal Typ As Integer) As Integer
End Function
End Class
This just defines a function, it doesn't get it from the dll.
Where is CharSet ? It's an Enum to say if you're using ASCII or Unicode, I *think*.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Tomorrow, I'll send you my source code. let you help me to check the problem. thank you for your support.
James
|
|
|
|
|
OK - I'll be happy to look for you.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi, Christian
Below is my VB .NET source code. There is one Click Button Sub. and other three test classes to wrap functions of DLL. 1st is using Declare Function. 2rd is using DLLImport. 3rd is a sample class for User32.dll. it's ok.
I think that the problem maybe parameter type mapping is error bewteen VC++ DLL and VB .NET. Please give me advise. thanks.
Best regars, jiannong
The VB .NET source code is below
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim gnNumOfDevice As Integer
Dim ErrCde As Long
Const SUCESS = &H0
Dim TestDll As TestDLL
Dim TestDll2 As TestDLL2
Dim devicelist As Long
Dim MaxEntries As Integer
Dim nOutEntries As Integer
Dim DeviceNum As Long
Dim DriverHandle As Integer
Dim ErrMsg As String
Dim ptDioWritePortByte As PT_WritePortByte1
Dim Port As Integer
Dim ByteData As Integer
DeviceNum = &H0
ErrCde = &H0
Dim testdll3 As TESTDLL3
testdll3.MessageBox(0, "Hello World", "Platform Invoke Sample", 0)
ErrCde = TestDll2.DRV_DeviceGetNumOfList(gnNumOfDevice)
ErrCde = TestDll.DRV_DeviceGetNumOfList(gnNumOfDevice)
ErrCde = TestDll.DRV_DeviceGetList(devicelist, MaxEntries, nOutEntries)
ptDioWritePortByte.Port = 0
ptDioWritePortByte.ByteData = &H55
ErrCde = TestDll2.DRV_DeviceOpen(DeviceNum, DriverHandle)
TestDll.DRV_GetErrorMessage(ErrCde, ErrMsg)
ErrCde = TestDll2.DRV_WritePortByte(DriverHandle, ptDioWritePortByte)
End Sub
Using Class to Declare DLL function
Imports System.Runtime.InteropServices
<structlayout(layoutkind.sequential)> Public Structure PT_WritePortByte
Dim Port As Integer
Dim ByteData As Integer
End Structure
<structlayout(layoutkind.sequential)> Public Structure PT_WritePortWord
Dim Port As Integer
Dim WordData As Integer
End Structure
'////////////////////////// V2.0C \\\\\\\\\\\\\\\\\\\\\\\\
<structlayout(layoutkind.sequential)> Public Structure PT_WritePortDword
Dim Port As Integer
Dim DwordData As Long
End Structure
'////////////////////////// V2.0C \\\\\\\\\\\\\\\\\\\\\\\\
<structlayout(layoutkind.sequential)> Public Structure PT_ReadPortByte
Dim Port As Integer
Dim ByteData As Long ' USHORT far *ByteData
End Structure
<structlayout(layoutkind.sequential)> Public Structure PT_ReadPortWord
Dim Port As Integer
Dim WordData As Long ' USHORT far *WordData
End Structure
'////////////////////////// V2.0C \\\\\\\\\\\\\\\\\\\\\\\\
<structlayout(layoutkind.sequential)> Public Structure PT_ReadPortDword
Dim Port As Integer
Dim DwordData As Long
End Structure
Public Class TestDLL
'////////////////////////// V2.0C \\\\\\\\\\\\\\\\\\\\\\\\
Declare Function DRV_SelectDevice Lib "adsapi32.dll" (ByVal hCaller As Long, ByVal GetModule As Boolean, ByVal DeviceNum As Long, ByVal Description As String) As Long
Declare Function DRV_DeviceGetNumOfList Lib "adsapi32.dll" (ByVal NumOfDevices As Integer) As Long
Declare Function DRV_DeviceGetList Lib "adsapi32.dll" (ByVal devicelist As Long, ByVal MaxEntries As Integer, ByVal nOutEntries As Integer) As Long
Declare Function DRV_DeviceGetSubList Lib "adsapi32.dll" (ByVal DeviceNum As Long, ByVal SubDevList As Long, ByVal MaxEntries As Integer, ByVal nOutEntries As Integer) As Long
Declare Function DRV_DeviceOpen Lib "adsapi32.dll" (ByVal DeviceNum As Long, ByVal DriverHandle As Long) As Long
Declare Function DRV_DeviceClose Lib "adsapi32.dll" (ByVal DriverHandle As Long) As Long
' Declare Function DRV_DeviceGetFeatures Lib "adsapi32.dll" (ByVal DriverHandle As Long, ByVal lpDevFeatures As PT_DeviceGetFeatures) As Long
Declare Sub DRV_GetErrorMessage Lib "adsapi32.dll" (ByVal lError As Long, ByVal lpszszErrMsg As String)
Declare Function DRV_WritePortByte Lib "adsapi32.dll" (ByVal DriverHandle As Long, ByVal WritePortByte As PT_WritePortByte) As Long
Declare Function DRV_WritePortWord Lib "adsapi32.dll" (ByVal DriverHandle As Long, ByVal WritePortWord As PT_WritePortWord) As Long
Declare Function DRV_ReadPortByte Lib "adsapi32.dll" (ByVal DriverHandle As Long, ByVal ReadPortByte As PT_ReadPortByte) As Long
Declare Function DRV_ReadPortWord Lib "adsapi32.dll" (ByVal DriverHandle As Long, ByVal ReadPortWord As PT_ReadPortWord) As Long
End Class
Using Class to declare function by DLLImport
Imports System.Runtime.InteropServices
<structlayout(layoutkind.sequential)> Public Structure PT_WritePortByte1
Dim Port As Integer
Dim ByteData As Integer
End Structure
Public Class TestDLL2
<dllimport("adsapi32.dll")> _
Public Shared Function DRV_DeviceGetNumOfList(ByVal NumOfDevices As Integer) As Long
End Function
Public Shared Function DRV_DeviceOpen(ByVal DeviceNum As Long, ByVal DriverHandle As Integer) As Long
End Function
Public Shared Function DRV_WritePortByte(ByVal DriverHandle As Integer, ByVal WritePortByte As PT_WritePortByte1) As Long
End Function
End Class
Try the sample, it’s Ok
Imports System.Runtime.InteropServices
Public Class TESTDLL3
Declare Auto Function MessageBox Lib "user32.dll" _
(ByVal hWnd As Integer, _
ByVal txt As String, ByVal caption As String, _
ByVal Typ As Integer) As Integer
End Class
|
|
|
|
|
I don't see anything wrong with the code. Where does the dll come from ? Can you send me a copy and I'll have a look ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
The DLL is Aventech Digit I/O PCI driver. Yah, The compiler said ok. But I cann't access the function in DLL. THanks.
Best regards, jiannong
|
|
|
|
|
Hello to Anyone
I am new to programming. I have set up a form with one datagrid. Using odbc connections to a progress 9.1c database I have been able to set up the datagrid to fill the data from one of the tables in the database. However I have not been able to get it to update data back to the table. I was hoping someone could send me in the right direction for finding good information on using odbc connection. The data connector did not build the sql strings for update or delete and I have added them to the properties page for the datadapter. But I am guessing that the code is not calling this when I do an update.
Would it be better to write all the code to make connections and datasets??
Any and all help would be greatly appreciated.
Mike
|
|
|
|
|
If you want to do things right use stored procedures. Also, any vb.net book has sqlcommand examples.
"People who never make mistakes, never do anything."
My blog
http://toddsnotsoamazinglife.blogspot.com/
|
|
|
|
|
I'm using a VB6 application with an FP Spread control. I need a way to check to see if the date was entered complete and in the right format. This is the idea that I have but does not work:
With fpsScr
If .ActiveCol = 6 And .ChangeMade Then
If .Text <> "##/##/####" Then
MsgBox "The date was not entered correctly. Please try again.",_
vbOKOnly, "Incorrect Date Entry"
End If
End If
End With
Can someone help me?
ryanchk
|
|
|
|
|
If .Text <> "##/##/####" Then
Replace this with:
if IsDate(.Text) then
|
|
|
|
|
thealca,
I appreciate you taking the time te help me. The solution checks to see if the field is a date but I also need to make sure that the date wasn't entered incorrectly, i.e. if someone just enters 5/05 I want to display the message to have them re-enter the date.
ryanchk
|
|
|
|
|
im creating a game cheating/game hacking utility and i was wondering if anyone has any examples of dll injection with vb.net
|
|
|
|
|
No, I doubt you can do that in VB.NET. VB exists to make it easy to write a certain type of application. To do powerful stuff you need C++.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I can't find a simple way to move a folder from one place to another without identical roots (directory.move, file.move), or even better, copy a folder, then paste it into another directory(without identical root).
|
|
|
|
|
I don't know if this is the right place to post this. But i'm new, and i'm very sorry if it's wrong
I have a school project, and must only use VBA
I would like to have VBA, to check if my variable contains any letters, symbols or numbers.
If it is an area code i have to tjek, then i would like to tjek for containing letters and symbols. And if it's a name i would like to tjek for symbols and numbers. Is this possible in VBA?
|
|
|
|
|
Anyone have any code that reads a number of records from a database table into a Dynamic Array?
macca
|
|
|
|
|
you can do two things :
1st way :
use an ArrayList and Add() each element you want...
2nd way :
select sum(column) from table...
then create a simple array (non redimentionable), which size is the length read previously...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Thanks for the reply toxxct, but do you have any example code for this?
macca
|
|
|
|
|
Dim RecordArray() as string
Dim SqlAdap as New sqlAdapter(QueryString,ConnectionString)
Dim RowTable as New datatable
SqlAdap.fill(RowTable)
Dim Myrow as Datarow
redim recordArray(rowtable.rows.count-1) as String
Dim i as integer=0
'If u need to inser all the fields from the row
' u can create two dimensional array
For each myrow in Rowtable.rows
recordArray(i) = myRow(0)
i+=1
next
Mandar Patankar
Microsoft Certified professional
|
|
|
|
|
If I double click on a row in my datagrid I want to bring up another form. How can I trap for the double click?
As I arrow up and down in my datagrid I want the entire row to be highlited not just a single cell. How can I do this?
Thanks for any help provided.
|
|
|
|
|
1.) just handle the DoubleClick event
you may noticed, the doubleClick event will be fired, if you doubleclick on the background of you grid, but not if you click into a cell. when you enter a cell a DatagridTextbox will come to front and catches the doubleclick. solution follows...
2.) you have to define your own columnstyle and override the onpaint-method. in onPaint differ between current row and not current row.
public Class YourColumnStyle
Inherits System.windows.Forms.DataGridTextBoxColumn
Protected Overloads Overrides Sub Edit(...)
' override and do nothing so DatagridTextBox wouldn't appear
End Sub
Protected Overloads Overrides Sub Paint(...)
If Me.DataGridTableStyle.DataGrid.CurrentRowIndex = rowNum Then
Else
End If
End Sub
End Class
how to implement a functional columnstyle is an other story
|
|
|
|
|
Thanks.
I'm a newbee at vb (long time user of FoxPro) but I'll try out your ideas.
When I did this type of thing in FoxPro I created a subclass of a textbox control which had code in its double click event. Then I added this textbox control to each column in my grid. Double clicking in any cell in the grid ran the textbox's double click event. This approach work well. Can I do this same type of thing in vb?
|
|
|
|