I am using OpenNetCF 2.3.0.39 and I am getting a hard crash when try to access the DnsAddresses.Count property. Is anyone familiar with this problem or a workaround?
Dim interfaces As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
For Each ni As NetworkInterface In interfaces
Dim ipProps As IPInterfaceProperties = ni.GetIPProperties()
If ipProps.DnsAddresses.Count > 0 Then
...
Related
I am using the ComponentOne Winforms suite, specifically the FlexReport control, to generate output which will be sent directly to one of several printers. This isn't, I believe, an issue with the ComponentOne suite as I was having similar issues with Crystal.
The end result will run as a VB .Net windows service, but I am having real problems getting it to work. The current code is as follows:
Dim factory As New DatabaseProviderFactory()
Dim sysDb As SqlDatabase
Dim dsOrderList As New DataSet
Dim dsOrderDetail As New DataSet
Dim frPicklist55 As New C1.Win.FlexReport.C1FlexReport
Dim p1 As C1.Win.FlexReport.ReportParameter
Dim options As C1PrintOptions = New C1PrintOptions()
options.PrinterSettings = New PrinterSettings()
options.PageSettings = New System.Drawing.Printing.PageSettings()
'options.PrinterSettings.PrinterName = "\\printsvr\printername"
'options.PrinterSettings.PrinterName = "\\\\printsvr\\printername"
options.PrinterSettings.PrinterName = "Printer1"
sysDb = factory.Create("sys")
dsOrderList = sysDb.ExecuteDataSet("sp_apispool_getorders")
For Each r In dsOrderList.Tables(0).Rows
dsOrderDetail = sysDb.ExecuteDataSet("sp_apispool_getorder", r("order_no"))
frPicklist55.Load("D:\API Spooling Docs\Rpt55Picklist.flxr", "Picklist")
frPicklist55.Parameters("OrderNo").Value = r("order_no")
frPicklist55.Render()
frPicklist55.Print(options)
Next
Specifically, the issues are:
If I use a shared printer ('\printsvr\printername' or '\\printsvr\printername'), I get an exception about the printer settings not being valid.
If I use the local printer ('Printer1'), I get an exception -'Operation is not supported'
This should be really simple, but I suspect I am missing something fundamental. No matter what I do I get an exception at the point I call the Print function.
Any ideas?
I have a vb.net code and want to convert it in vb 6.0. But I have some difficulties. I cant find equivalent of some .net classes
Dim byteswritten As Integer
Dim fs As System.IO.FileStream
Dim r As System.IO.BinaryReader
Dim CHUNK_SIZE As Integer = 65554
fs = New System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
r = New System.IO.BinaryReader(fs)
Dim FSize As Integer = CType(fs.Length, Integer)
Dim chunk() As Byte = r.ReadBytes(CHUNK_SIZE)
While (chunk.Length > 0)
dmPutStream.Write(chunk, chunk.Length, byteswritten)
If (FSize < CHUNK_SIZE) Then
CHUNK_SIZE = FSize
chunk = r.ReadBytes(CHUNK_SIZE)
Else
chunk = r.ReadBytes(CHUNK_SIZE)
End If
End While
Well, the document can be big then we used chunk. But I dont know steps for vb 6.0
Such as what i should do for binary reading.
Without all your code for opening the write stream and closing the read and write streams, here's an example of how you can do it in VB6 using ADODB.Stream.
Under Project | References, add a reference to ADO Active X Data Objects Library. My version is 6.1, but you should be okay to just choose the latest version - depends on what version of ADO is installed on your system
Hope it helps - more info online if you want to look at all the ADODB.Stream methods and properties
Public Sub StreamData(strWriteFilename As String, filePath As String)
Const CHUNK_SIZE As Long = 65554
Dim byteswritten As Integer
Dim FSize As Long
Dim adofs As New ADODB.Stream 'Object 'System.IO.FileStream
Dim varData As Variant
' Include this here - but probably defined elsewhere
Dim dmPutStream As New ADODB.Stream
' Open Write Stream
' *** Looks like you do this elsewhere
Set dmPutStream = CreateObject("ADODB.Stream")
With dmPutStream
.Type = adTypeBinary
.Open strWriteFilename, adModeWrite
End With
' Open Read strema and start pushing data from it to the write stream
Set adofs = CreateObject("ADODB.Stream") 'New System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
With adofs
.Type = adTypeBinary
.Open
.LoadFromFile filePath
' Size of Read file - do you want this?
FSize = .Size
varData = .Read(CHUNK_SIZE)
Do While Len(varData) > 0
dmPutStream.Write varData
If Not .EOS Then
varData = .Read(CHUNK_SIZE)
End If
Loop
.Close
End With
'Save binary data To disk
dmPutStream.SaveToFile strWriteFilename, adSaveCreateOverWrite
dmPutStream.Close
End Sub
Converting VB.NET to VB6 is a bad idea, and completely unnecessary. If you need to use the VB.NET code from a VB6 application, the best thing to do would be to create a COM-visible wrapper for your .NET library, and call that wrapper from your VB6 application.
You probably CAN convert the code functionally with VB6, but there really is no point. VB.NET is a better language than VB6, use its COM capabilities to save you from writing endless sketchy VB6 code.
If you are dead set on doing this, you will need to reproduce the Stream and Reader classes functionally.
Here is the source for FileStream.cs:
http://referencesource.microsoft.com/#mscorlib/system/io/filestream.cs
And for BinaryReader:
http://referencesource.microsoft.com/#mscorlib/system/io/binaryreader.cs
I have tried to get the MAC address of each network interface card on a machine by using the below function in VB.NET, but I just realized that this function doesn't work in Windows XP:
Function getMacAddress()
Dim nics() As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces()
Return nics(1).GetPhysicalAddress.ToString
End Function
How can I make this code to run on Windows XP? What other alternatives exist to get the list of MAC addresses on Windows XP?
I did some digging when connecting to different VPNs. So far the below seems pretty reliable. Relying on 0 or 1 for the actual physical adapter as suggested above does not work in many cases. In some cases my actual Ethernet adapter was the 3rd adapter. Excluding the loopbacks, tunnels, and ppp adapters should narrow it down. I found that many of my non physical adapters have the string "00000000000000E0" as the mac address.
Private Function getMacAddress() As String
Try
Dim adapters As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
Dim adapter As NetworkInterface
Dim myMac As String = String.Empty
For Each adapter In adapters
Select Case adapter.NetworkInterfaceType
'Exclude Tunnels, Loopbacks and PPP
Case NetworkInterfaceType.Tunnel, NetworkInterfaceType.Loopback, NetworkInterfaceType.Ppp
Case Else
If Not adapter.GetPhysicalAddress.ToString = String.Empty And Not adapter.GetPhysicalAddress.ToString = "00000000000000E0" Then
myMac = adapter.GetPhysicalAddress.ToString
Exit For ' Got a mac so exit for
End If
End Select
Next adapter
Return myMac
Catch ex As Exception
Return String.Empty
End Try
End Function
Works for me on XP, except I've got a few interfaces and my first (0th) is my "real" MAC address, and it corresponds to the MAC address reported by a non-.NET program.
I'm working on an old project in asp
I've never worked with vb6 or asp before I am a .net developer
anyway
I made a .net dll and changed some compile options to make it work with vb6
the code doesnt matter
I made a "wrapper kinda" dll in vb6
Public Function EncryptWrapper(ByVal parameterstring As String, ByVal isShaIn As String, ByVal HashType As String) As String
Dim o
Set o = CreateObject("SHA1Module.Conversion")
EncryptWrapper = CStr(o.EncryptToSHA1(CStr(parameterstring), CBool(isShaIn), CLng(HashType)))
End Function
and a form in vb6 that calls it
Private Sub Command1_Click()
Dim message
Dim myObject
Set myObject = CreateObject("SHAModuleWrapper.Encryption")
message = myObject.EncryptWrapper(txtIn.Text, "1", "2")
Set myObject = Nothing
txtOut.Text = message
End Sub
this works perfectly
now in asp I try calling that dll and I get an error
<% Dim strMessage
Dim message
strMessage = "hello"
Dim myObject
Set myObject = Server.CreateObject("SHAModuleWrapper.Encryption")
message = myObject.EncryptWrapper("testdagtestdagtest", "1", "0")
Response.Write(message)
%>
this is the error message
SHAModuleWrapper error '800a0005'
Invalid procedure call or argument
/asptest/Default.asp, line 15
It's not the parameters or the output
it's this part that is causing the trouble
**Dim o
Set o = CreateObject("SHA1Module.Conversion")
EncryptWrapper = CStr(o.EncryptToSHA1(CStr(parameterstring), CBool(isShaIn), CLng(HashType)))**
Does anybody have an idea?
Dim o
Dim message
Dim myObject
These lines are cause for concern. These will be a variant as they are not a defined type.
Option Explicit is your friend in VB6 - use it always!
Have a look at this link: Avoid program bugs in VB6 with the Option Explicit statement for more information.
A lot of frustration and batch files later I found the solution.
I needed to create a strong name for my assembly and register it in the GAC
This is a good step by step tutorial on how to solve this issue
Tutorial
these 2 steps helped me
8) Generate a public/private key pair
sn -k MarkItUp.key
9) Add the attribute to my assembly for registering it:
<Assembly: AssemblyKeyFile("C:\MarkItUp.key")>
in your bad code you have
Set o = CreateObject("SHA1Module.Conversion")
should it be
Set o = CreateObject("SHA1Module.Encryption")
Check that IUSR_Machine has permission to execute your dlls.
Example:
Dim Sh32 As Object = CreateObject("Shell.Application")
Dim path As String = "C:\temp\catalog.zip"
Dim sf As Object = Sh32.NameSpace(path)
-> does not work, sf = Nothing
Dim Sh32 As Object = CreateObject("Shell.Application")
Dim path As String = "C:\temp\catalog.zip"
Dim sf As Object = Sh32.NameSpace(path.ToString)
-> works
Any idea?
Clearly path = path.ToString, but they behave differently when used as COM parameters.
Hmm, I don't know the details of VB and/or COM well enough, but maybe there is a difference between a string object and a string representation?
Should be interesting to see someone "in the know" resolving the puzzle ;)