|
Good Morning!
I have a program developed in C, but the main application was made in Visual Basic. Is there any way of accessing C functions from Visual Basic?
My best regards.
|
|
|
|
|
ajorge2008 wrote: Is there any way of accessing C functions from Visual Basic?
Visual Basic or Visual Basic .NET ?
You need to export your C functions to a DLL. Use P-Invoke to access that in your .NET application.
|
|
|
|
|
Hello guys,
in my search for a solution integrating an ActiveX Object I received a code snippet for a class to convert the IPicture format first:
Private NotInheritable Class myClass
Inherits System.Windows.Forms.AxHost
Public Shared Shadows Function GetPictureFromIPicture(ByVal picture As Object) As Image
Return AxHost.GetPictureFromIPicture(picture)
End Function
End Class and I should use it like
Dim pic As Bitmap = MyClass.GetPictureFromIPicture(GflAxObj.GetPicture) The first trap I run into is that obviously VB requires "a private type to be within another type" (hope it's translated good enough from my german version that you understand what I mean). I have no idea what's meant and can't find any hints in the help files and internet...
Trying to make the class public VB tells me it would require a "sub...new" with reference to mybase.new and it's parameters. But this fails because I don't even know which parameters I might have to use.
One more: The last line in the code snippet "Dim pic as ..." refers to the ActiveXObject as "GflAxObj", but I can't see where it is defined. I'm afraid this would be one of the next traps.
Could someone please give me some guidance through this?
Thank you very much
Michael
|
|
|
|
|
First of all i'm sorry if there is already an answer to this question but I looked for approximately an hour and couldn't find one so i'm asking it.
I'm trying to create conditional logic which includes a "and or" statement but apparently it doesn't work. I was wondering if there is a way to do this or at least emulate it. The code is something like this If textbox1.text = Nothing And Checkbox1.Checked = True And Or Checkbox2.Checked = False Then... Thanks for any responses in advance.
modified 8-Sep-21 21:01pm.
|
|
|
|
|
Saying "and/or", if I understand it right, means "if any of them is true"; which means just the Or operator. I might be wrong, the Or in English language means either one of two is true but not both while the Or in Logic means either one of two is true but if both are true, it's ok.
English Or (known in programming as XOr )
flase or false => false
flase or true => true
true or false => true
true or true => false
Logical Or
false or false => false
false or true => true
true or false => true
true or true => true
Eslam Afifi
|
|
|
|
|
You cant try it .
if (textbox1.text = Nothing And Checkbox1.Checked = True And Checkbox2.Checked = False) or (textbox1.text = Nothing And Checkbox1.Checked = True or Checkbox2.Checked = False)
Regard
Anubhava Dimri
Anubhava Dimri
|
|
|
|
|
Brian Wernick wrote: The code is something like this If textbox1.text = Nothing And Checkbox1.Checked = True And Or Checkbox2.Checked = False Then...
Not sure what you want the And OR to do. You could use something like:
If (String.IsNullOrEmpty(TextBox1.Text) AndAlso CheckBox1.Checked = True ORELSE CheckBox2.Checked = False) Then
ANDALSO and ORELSE allows the code to shortcircuit if the evals fail. Instead of checking if the textbox1.text = nothing, use string.IsNullOrEmpty which will check for both a null reference or empty string value.
If in doubt how your checks will evaluate to, put a break point on the line to pause execution. You can then break out the checks on at a time into the watch or immediate window to ensure your getting the results your expecting.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
|
|
|
|
|
Hi,
I'm new to programming and thought that VB was an easy bus to hop on....
Currently I'm working through Visual Basic 2008 Step by Step.
And indeed, taking it step by step, I'll get there.
But for now I stand still.
I want to enable a button only when an user scrolled all the way down in a textbox.
I wanted to use the VScrollProperties of the scrollbar in the TextBox.
There are upper and lower limits wich gets or sets the range of the scrollbar, but I don't see how to use them as an Event Handler.
Carol
|
|
|
|
|
I do not believe their is an easy way to communicate with the scrollbar in the textbox. To do that you may have to resort to using WinAPI, however you might be able to monitor clicks in the control and see which lines are visible (if the last line is visible then the scrollbar is at the bottom).
If you look into the WinAPI, you would also look into the WndProc function of the textbox control.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
hai guys, i am using inet to upload a picture to imageshack.
but my code does not work. cant find the problem.
pls help
Private Sub Command1_Click()
Dim intFile As Integer '// Next available number for the Open statement
Dim ImageData As String '
Dim Body As String '// Body contents
Dim Header As String '
'// Get the image contents
imagepath = App.Path & "\" & "test.jpg" ' max 3mb image size limited
intFile = FreeFile
Open imagepath For Binary As #intFile
ImageData = String(LOF(intFile), Chr(0))
Get #intFile, , ImageData
Close #intFile
Body = "Content-Disposition: form-data; name=""fileupload""; filename=""" & vbCrLf
Body = Body & "Content-Type: multipart/form-data" & vbCrLf
Body = Body & vbCrLf & ImageData
Header = "Host: imageshack.us" & vbCrLf
Header = Header & "Content-Type: multipart/form-data & vbCrLf"
Header = Header & "Content-Length: " & Len(ImageData) & vbCrLf & vbCrLf
'upload now
Inet.Execute "http://www.imageshack.us", "POST", Body, Header
While Inet.StillExecuting
DoEvents
Wend
Dim s$, ret$
s = Inet.GetChunk(1024)
Do Until s = ""
ret = ret & s
s = Inet.GetChunk(1024)
Loop
'check upload completed
If InStr(1, ret, "Show Advanced Linking") > 0 Then MsgBox "upload completed"
End Sub
|
|
|
|
|
afridy wrote: my code does not work
This is not an adequate statement of a problem. I will be astonished if someone will audit your code for you.
You need to give us some idea of what the problem is and where it occurred.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
intFile = FreeFile 'where is FreeFile declared?
Header = Header & "Content-Type: multipart/form-data & vbCrLf" 'do you really want vbCrLf included in that string?
I got that far and gave up, what are you trying to do
|
|
|
|
|
thank you for the reply Eliotta,
freefile is a built in vb file i/o fuction right?
|
|
|
|
|
|
ok eliotta, i added the link in my prevous post to the original project i am referring to.
|
|
|
|
|
yah i am not sure about my header and body compilation.
i just copied that from a code and compilied.
let me give the url of that code i was referring to.
ill edit an append here the url to that code in a min.
<a href="http://planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=69883&lngWId=1">http:
|
|
|
|
|
When you use the DLLImport attribute to declare an API declaration there is a CharSet property that tells which version of the API call to use - Ansi, Unicode or CharSet.Auto in which case either the operating system or the language decides (for example C# defaults to ANSI for some reason).
How can I know which version was actually called if I specified CharSet.Auto? Any thoughts?
|
|
|
|
|
It's the platform that decides, not the language. CharSet.Ansi targets the widest range of available platforms (Windows 95/98 without Unicode extentions.) The Ansi versions are still available on NT kernel platforms so Ansi will still work if forced. Auto will prefer Unicode if it's available. If not, it'll drop back to Ansi versions without any intervention from your code.
|
|
|
|
|
Hi All,
can anybody guide me how can i customize "OpenFileDialog" in vb.net. Actually i want a preview window with "OpenFileDialog" at the bottom...
many thanks,
|
|
|
|
|
Best way to create a custom dialog is by creating a form that mimics what you want done. There are numerous articles out there how to do so.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Dear Paul,
would u plz tell me web address of such articles... thanks again...
|
|
|
|
|
onlyehtisham wrote: thanks again...
Don't down vote someone helping you. That's just rude.
onlyehtisham wrote: would u plz tell me web address of such articles...
Ummmm, do a search on this site.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Paul,
I agree with the rudeness of voting you down. I guess I will not bother to help him.
Jeff
|
|
|
|
|
Yep. Don't worry about it, man.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
I am confused with the UDP Socket when used with an Async call - The code works ok - as long as the client is online - if the client is offline - i end up with many unclosed sockets.
I am running the code repeatedly to many different clients for polling SNMP devices.
For some reason the first time the code is run and hits an offline client - an object disposed exception occurs. each successive call just leaves an open socket when hitting an offline client. all other times - as long as the client is online the sockets are closed neatly.
ultimately this code needs to run repeatedly non-stop to poll many devices 100+
<code>Public Class UDPStateObject
Public Endpoint As IPEndPoint
Public buffer(1024) As Byte ' Receive buffer.
Public udpSocket As Socket = Nothing
End Class
Public Sub SendSNMP(ByVal request As SNMPRequest)
Dim sobj As New UDPStateObject
Dim UDPServ As New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
Dim ipAdd As IPAddress = IPAddress.Parse(request.IPAddress)
Dim remoteEP As New IPEndPoint(ipAdd, 161)
Dim packet As Byte() = buildPacket(request)
Try
sobj.udpSocket = UDPServ
sobj.Endpoint = remoteEP
Dim localEP As New IPEndPoint(IPAddress.Any, 0)
sobj.udpSocket.Bind(localEP)
sobj.udpSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 4000)
sobj.udpSocket.SendTimeout = 4000
sobj.udpSocket.BeginSendTo(packet, 0, packet.Length, SocketFlags.None, remoteEP, New AsyncCallback(AddressOf PacketSent), sobj)
Dim sresult As Boolean = sendDone.WaitOne(4000, False)
If Not sresult Then
utils.WriteErrorLogEntry("SNMPTx Timeout")
Else
'-----------------------------------------------------------------------------------
Dim ipe As New IPEndPoint(remoteEP.Address, localEP.Port)
sobj.udpSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 8000)
sobj.udpSocket.ReceiveTimeout = 8000
sobj.udpSocket.BeginReceiveFrom(sobj.buffer, 0, 1024, SocketFlags.None, ipe, New AsyncCallback(AddressOf ReceivePacket), sobj)
Dim rresult As Boolean = receiveDone.WaitOne(8000, False)
If Not rresult Then
utils.WriteErrorLogEntry("SNMPRx Timeout")
If sobj.udpSocket.IsBound Then
utils.WriteErrorLogEntry("SNMP IsBound")
sobj.udpSocket.Close()
End If
End If
'-----------------------------------------------------------------------------------
End If
Catch ex As SocketException
RaiseEvent onError(ex.ToString, "Send SNMP Error", request.IPAddress)
End Try
End Sub
Public Sub PacketSent(ByVal ar As IAsyncResult)
Try
Dim srv As UDPStateObject = CType(ar.AsyncState, UDPStateObject)
Dim bytesSent As Integer
Try
bytesSent = srv.udpSocket.EndSend(ar)
Catch ode As ObjectDisposedException
RaiseEvent onError("SNMPTx Sent - Socket Disposed " & ode.Message, "No Socket", srv.Endpoint.Address.ToString)
Exit Sub
End Try
sendDone.Set()
If bytesSent > 0 Then
'ok
Else
srv.udpSocket.Close()
End If
Catch ex As SocketException
RaiseEvent onError(ex.ToString, "Packet Sent SNMP Error:" & ex.ToString, "")
End Try
End Sub
Sub ReceivePacket(ByVal ar As IAsyncResult)
Dim ipstr() As String = {"", ""}
Dim client As UDPStateObject = CType(ar.AsyncState, UDPStateObject)
Dim BytesReceived As Integer = 0
Try
BytesReceived = client.udpSocket.EndReceive(ar)
Catch ode As ObjectDisposedException
RaiseEvent onError("SNMPRx Receive - Socket Disposed " & ode.Message, "No Socket", ipstr(0))
Exit Sub
End Try
receiveDone.Set()
Dim snsa As SocketAddress = client.Endpoint.Serialize
Dim ipe As New IPEndPoint(IPAddress.Any, 1000)
Dim ep As EndPoint = ipe.Create(snsa)
ipstr = ep.ToString.Split(":")
If BytesReceived > 0 Then
Dim x As Byte() = client.buffer
Dim resp As SNMPResponse = decodePacket(x, ipstr(0))
RaiseEvent UDPDataRx(resp, ipstr(0))
Else
RaiseEvent onError("SNMPRx Receive Packet - Empty Buffer", "No Client", ipstr(0))
End If
End Sub</code>
|
|
|
|