|
Hi,
I have a VB.Net app that for various reasons is required to load a dll written in C using the LoadLibrary and (when done) FreeLibrary APIs. For the most part everything works perfectly. However there is a problem with one of the functions in the dll, which simply writes an empty file in the users temp directory. When called via the VB.Net app using the following code:
pFunction = GetProcAddress(hDllInstance, f)
If Not pFunction.Equals(System.IntPtr.Zero) Then
Try
CallWindowProc(pFunction, 0, 0, 0, 0)
Catch ex As Exception
End Try
End If
a System.NullReferenceException is always thrown. The file however is written correctly. The function in the dll is simply:
void CreateTempFile()
{
HWND hWnd = CreateFile(szFilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL);
CloseHandle(hWnd);
}
The szFilePath parameter is 1024 chars long (ie. no buffer overruns) and contains the name of the file to create. I created a test program in C to load and test the dll functions and this ran perfectly, both standalone and when run stepwise in a debugger. No exceptions or buffer overruns (etc.) occurred.
I am running the VB.Net app with administrator priviledges. Any ideas would be gratefully received.
Thanks
|
|
|
|
|
I don't think CallWindowProc is going to work for you. I also don't think you can make a direct call to unmanaged code like this.
You might want to take a look at this[^] for an example.
There's also a couple of C# examples here[^]. I don't see an reason why the code couldn't be converted to VB.NET.
Dave Kreskowiak
Microsoft MVP - Visual Basic
-- modified at 20:12 Thursday 13th July, 2006
|
|
|
|
|
Thanks for your reply, this was much appreciated. In actual fact all the calls to CallWindowProc do work, its just that any call that creates a file also raises an exception. I couldn't access the first example you gave (I'm not a paid up member of Experts Exchange) however the other example has given me food for thought. Thanks again for this.
|
|
|
|
|
Hmmm...Things look like they change at the Experts Exchange. I never paidfor a subscription!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Just out of interest the System.NullReferenceException was being thrown as I had declared the CallWindowProc function as:
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As IntPtr, ByVal hWnd As Long, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As String
I "cast" the return value to a string as I would subsequently call this function again to run procedures in the unmanaged dll that returned string values, and I knew no other way to read a string value from memory in .Net Even though I wasn't using the return value in the initial call to CallWindowProc the interop services obviously still attempted to use the value in eax as the address of a string, with the resulting exception being thrown. Simply declaring the return value as an Integer fixed the problem.
|
|
|
|
|
hi i had get the color through color dialog box and saved them in database nd then i want to set on the form?
then i want to set the color of dalog reading from the datbase but it gives error that cannot change readonly property.
System.drawing.color clr=new color();
clr.A=a;//read from db; //gives error that cannot change readonly property
.R=b;
.B=v//et
now i want to set the form color to this.
this.color=clr;
how to assign values to color variables?
Tasleem Arif
|
|
|
|
|
You can't change a color structure once you created it. Use the FromArgb method to create a color from the color components:
clr = Color.FromArgb(a, r, g, b);
---
b { font-weight: normal; }
|
|
|
|
|
Hi. I was wondering how I could use VB.Net code in VS2005 to split a wave file. I am new here I would like to learn some. I don't want others doing my work for me but I would like suggestions! I want to specify the time at which the wave file would be split into two different wave files where I could then save them as separate wave files. Does anybody have a clue? Please! I really need help!
Came here from VBForums......Thought people here could help me.
"Imagination is more important than knowledge." - Albert Einstein.
|
|
|
|
|
A wave file consists of a header and sound data. The header contains data like sample rate and sample size, that you need to know how the sound data is arranged.
What you need to do is to reader the header and the sound data, and construct new headers for the two new files, and split the sound data at the sample you calculate to be at the specified time.
One good source for file formats is Wotsit's format[^].
---
b { font-weight: normal; }
|
|
|
|
|
Hi, I am trying to populate a ComboBox with the contents obtained within an ArrayList, but instead of putting the names held within the ArrayList, it writes "System.Collections.ArrayList" in the place of the desired names.
Could you take a look at my code and see where I am going wrong.
I am using vb.net 2002 version.
Any help is greatly appreciated.
Many thanks
John
This is the code for the function selectFieldNames :-
Public fieldNames As New ArrayList()<br />
<br />
Public Function selectFieldNames(ByVal strSQL As String) As ArrayList<br />
' select all field names from the selected table<br />
sqlite_cmd.CommandText = (strSQL)<br />
' Now the SQLiteCommand object can give us a DataReader-Object:<br />
sqlite_datareader = sqlite_cmd.ExecuteReader()<br />
While sqlite_datareader.Read()<br />
Try<br />
fieldNames.Add(sqlite_datareader("name"))<br />
MessageBox.Show(sqlite_datareader("name"))<br />
Catch es As Exception<br />
MessageBox.Show(es.Message)<br />
End Try<br />
End While<br />
Return fieldNames<br />
End Function
This is the code for populating the ComboBox :-
Private Sub frmCreateIndex_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
dbConn.openExistingDatabse("Data Source=" & getDBName() & ";Version=3;New=False;Compress=True;")<br />
dbConn.createSQLCommand()<br />
<br />
Dim a As Integer<br />
<br />
Try<br />
dbConn.selectFieldNames("pragma table_info(test)")<br />
For a = 0 To (dbConn.fieldNames.Count) - 1<br />
cmbFieldIndex.Items.Add(dbConn.fieldNames)<br />
Next a<br />
Catch es As Exception<br />
MessageBox.Show(es.Message)<br />
End Try<br />
End Sub
|
|
|
|
|
You setup an indexer to go through all the elements of fieldNames but you never used it to return an actual element in the array!
Try
dbConn.selectFieldNames("pragma table_info(test)")
For a = 0 To (dbConn.fieldNames.Count) - 1
cmbFieldIndex.Items.Add(dbConn.fieldNames)
Next a
Catch es As Exception
MessageBox.Show(es.Message)
End Try
Should be:
Try
dbConn.selectFieldNames("pragma table_info(test)")
For a = 0 To (dbConn.fieldNames.Count) - 1
cmbFieldIndex.Items.Add(dbConn.fieldNames(a))
Next a
Catch es As Exception
MessageBox.Show(es.Message)
End Try
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi, thanks for this, works a treat, I can't blieve I forgot to use the array.
Thanks again
John.
|
|
|
|
|
I want to develop sqlserver monitor ,tunerand analyzer please can you guide me how can i do this .. just give me a guideline .. or any opensource lib and prj u know
Features should include: Monitor SQL Server Hardware
requirements are
Utilization and Performance
Monitor CPU, memory, and the I/O subsystem percentages
Monitor disk operations (reads/writes) and network traffic
Correlate system utilization with user connections and SQL code
Diagnose Executed SQL Code Performance, Connections, and SQL Server Blocking
Analyze and chart slow performing SQL statements and stored procedures
Report the cost (Duration, CPU time, & disk reads/writes) of each statement
etc etc
R A M
|
|
|
|
|
SQL Server registers and populates a large number of performance counters - you can use the built in .NET class "PerformanceCounter" to get the current values from that for the first part of your requirement.
For the second part use the "SHOWPLAN" T-SQL commands.
'--8<------------------------
Ex Datis:
Duncan Jones
Merrion Computing Ltd
|
|
|
|
|
When I try to view a report inserted as Cerstal Report 11 report, LogOn Failed. I m using Orcle 8i Database.
|
|
|
|
|
I have a table with one column. This table has more than 1500 rows.
I want to print those 1500 rows of one column using 4 columns in the report(rdlc).
How is it possible?
|
|
|
|
|
This thing has driven me nuts the entire afternoon!
We have this unit to which we communicate over serialport that wants messages
in Unicode code points where C = 43, D = 44 etc.
If I want ASCII value for A i use Microsoft.VisualBasic.Asc("A") and get 65, problem is that A in Unicode is 41.
What to do??
|
|
|
|
|
|
jimithing77 wrote: A i use Microsoft.VisualBasic.Asc("A") and get 65,
As it should be. The decimal ASCII value is 65.
jimithing77 wrote: problem is that A in Unicode is 41
Not, it's not, it's 65. Convert decimal65 to hexadecimal and you get 41, or in VB notation &H41.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I'm sure there is a way to do it. But I don't have time to look, so I was just going to suggest that if you can't find a way, you could always write your own function that looks it up for you, like this:
Public Function GetCode(str as string) as Integer
Select Case str.Trim.ToUpper
Case "A"
Return 41
'Continue with other cases...
End Select
End Function
Or if you discover that the Microsoft.VisualBasic.Asc is consistant you could just say cint(Microsoft.VisualBasic.Asc(char)) - 24
Sorry I couldn't find a nicer answer.
|
|
|
|
|
Ah... I did think they were the same, but I didn't spot that little wrinkle when I read it, I just filed it as something to check on later.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Well, consider it checked then!
Something just looked familiar, and wrong, about those two numbers the way he was describing them. I knew 65(dec) was uppercase A, but 41?? Not in any character table I've ever seen! Then I opened the ASCII chart in Visual Studio Help and the problem was staring me right in the face.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I am using VB.NET (2003) to create a Windows form to interface with a SQL 2000 database. I need to validate the user input of an employee number with the table that contains the valid numbers. All I want to do is validate the information and move on, or pop a messagebox up. My problem is getting the code right to loop the array for the comparison function.
I also hope to match the USERID and integrate this into the validation process to further verify that the proper person is being identified.
Thank you in advance.
LW
LWhite
|
|
|
|
|
i don't know if this will help you but i hope it will
my suggestion is:
1. you save the use input in a variable
2. query database for that input
3. if the query result is 0 then the employee number is not exist, give warning
4. else then number is exist go to next process
I'm assuming you have a table called TabEmployees with a field called EmployeeNo and using microsoft access 2000 database file. here's the code
private function isEmpExist(byval EmpNo as integer) as boolean
dim CN as new oledbconnection
dim R as integer
cn.connectionstring="provider=microsoft.jet.oledb.4.0"
dim Cmd as oledbcommand=cn.createcommand
with cmd
'set commandtype as commandtext
.commandtext="SELECT EmployeeNo FROM TabEmployees WHERE EmployeeNo = " & EmpNo.tostring.trim
end with
r=cmd.executenonquery
if isnothing(r) then
return false
else
return true
end if
cn.close
end function
hope you find this useful, and i'm sorry if this code doesn't do as it should, but i think it will only might produce syntax error, coz i'm typing it directly here without VB. well then good luck!
|
|
|
|
|
ups sorry, i think i made mistake in that code, the line
r=cmd.executenonquery should have been
r=cmd.executescalar , sorry...
|
|
|
|