|
how can i do that?can u show me an example.
|
|
|
|
|
Example from MSDN:
Public Sub ReadMyAppSettings()
Dim appName As String
appName = ConfigurationSettings.AppSettings("Application Name")
Console.WriteLine()
Console.WriteLine("Reading AppSettings")
Console.WriteLine("Application Name: " & appName)
End Sub
The ConfigurationSettings class is in the System.Configuration namespace.
---
b { font-weight: normal; }
|
|
|
|
|
Hi guys,
When I used visual studio 7, to send a mail I used System.Web.mail.namespace .
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Imports System.Web.Mail
Public Class Form1
Dim obj As System.Web.Mail.SmtpMail
Dim Attachment As System.Web.Mail.MailAttachment
Dim message As New System.Web.Mail.MailMessage()
Private sub send_Mail()
obj.SmtpServer = text_Server.txt
message.to = text_To.txt
message.from = "\" & txtFromDisplayName.Text & "\ <" & txtFrom.Text & ">"
message.BodyFormat = MailFormat.Text
message.Subject = text_Subject.Text
message.Body = txtMessage.Text
Try
obj.Send(message)
catch ex as Exception
MsgBox("Problem with sending..please retry!",,"Attention!")
End Try
End sub
End Class
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Now in Visual Studio 2005 (8), when I try the same code, the program "suggests" me to use the latest System.Net.Mail.namespace because System.Web.Mail.namespace is absolete!
So,is there someone to help me with this? I try to find examples in Web, but I find only examples in C# .net not in vb .net. Help me please!
Thanx in advance.. ;)
|
|
|
|
|
The syntax is mostly the same. Use:
<br />
Dim obj As System.Net.Mail.SmtpClient <br />
Dim Attachment As System.Net.Mail.Attachment<br />
Dim message As New System.Net.Mail.MailMessage<br />
A couple of the parameters are different - for example .host instead of .SmtpServer, but apart from that it's pretty much the same. Intellisense should be able to fill in anything else you need.
|
|
|
|
|
Hi,
I'm interested to have a tool such as Spy++ in Microsoft Visual Studio. I'd like to get from a control
the value (ex: to get from a textbox the value) with another small application.
If somebody have ideea how is possible to do this please write.
Thanks.
biglewy
|
|
|
|
|
Hello together,
I should use C-Dll provided functions (constructed with VS.NET) in my
VB.Net program.
The dll-functions realise the communication via RS232 with a module. Executing the functions works well, but I can't receive the module-answers.
The answer is in a struct "rc_status" as follow:
//C-Dll Code
struct rc_status {
int status1;
int status2;
int status3;
int status4;
};
struct serialHandle {
HANDLE handle;
};
EXPORT struct rc_status *command01 (struct serialHandle *h, int mode, _ struct rc_status **status);
//VB.Net Code
<structlayout(layoutkind.sequential)> Public Structure rc_status
Dim status01 As Integer
Dim status02 As Integer
Dim status03 As Integer
Dim status04 As Integer
End Structure
Declare Function lc_command01 Lib "lcomp.dll" Alias _
"command01" (ByVal lc_serialHandle As Integer, ByVal mode As Integer, ByRef lc_status As rc_status) As IntPtr
since days, I tried hard - nothing works - germany can't help!
I'm very happy about every tip!
best regards from south germany,
Daniel
|
|
|
|
|
Daniel,
You need to set yourself up a some test code to debug what it is doing,
There could be "multiple reasons" for it failing to return that structure.
One I can see in the code you supplied is the structure may need to be
Initialized New prior to the call to lc_command01, or you may need to marshal
that structure.
But first I would code a way to debug it....so I could see what it was doing...
Somthing like...
Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential)> _
Public Structure rc_status
Dim status01 As Integer
Dim status02 As Integer
Dim status03 As Integer
Dim status04 As Integer
End Structure
Private Declare Function lc_command01 Lib "lcomp.dll" Alias "command01" ( _
ByVal lc_serialHandle As Integer, _
ByVal mode As Integer, _
<[In](), Out()> _
ByVal lc_status As rc_status) _
As Integer
Private Sub test(ByVal hSerial As Integer, ByVal iMode As Integer)
Dim retval As Integer
Dim sStatus As rc_status = New rc_status
retval = lc_command01(hSerial, iMode, sStatus)
Debug.WriteLine("Error Code: " & Marshal.GetLastWin32Error())
'/// Do whatever with retval and sStatus here ---
Debug.WriteLine("retval: " & retval)
Debug.WriteLine("status01: " & sStatus.status01)
Debug.WriteLine("status02: " & sStatus.status02)
Debug.WriteLine("status03: " & sStatus.status03)
Debug.WriteLine("status04: " & sStatus.status04)
'///---------------------------------------------
End Sub
progload
|
|
|
|
|
hi,
thank you very much -
i will do that immediately and post the debug-prints!
today,it's a snowy good day for vb.net
greets,
|
|
|
|
|
hi,
my test code debug-results are not spectacular, but difficult to understand :
Error Code: 0
retval: 1241740
status01: 0
status02: 0
status03: 0
status04: 0
//sign of life; debug-prints form the dll:
Hello Command01!
mode: 1
Dumped sm_idle command code: 03 14 01 16
Dumped sm_idle answer code: 03 14 01 16
Das Programm "[2248] WindowsApplication2.exe" wurde mit Code 0 (0x0) beendet.
I also tried the marshal "ptrToStructure" method (source: codeproject/adnan samuel - marshaling structures) :
Imports System.Runtime.InteropServices
< StructLayout(LayoutKind.Sequential)> _
Public Structure rc_status
Dim status01 As Integer
Dim status02 As Integer
Dim status03 As Integer
Dim status04 As Integer
End Structure
Declare Function command01 Lib "lcomp.dll" Alias "command01" ( _
ByVal lc_serialHandle As Integer, _
ByVal mode As Integer, _
ByRef lc_status As IntPtr) _
As Integer
Public Function test(ByVal hSerial As Integer, ByVal iMode As Integer)
Dim retval_int As Integer
Dim retval_ptr As IntPtr
Dim arg_ptr As IntPtr
Dim sStatus As rc_status = New rc_status()
Dim rc_sStatus As rc_status = New rc_status()
Dim gh As GCHandle = GCHandle.Alloc(sStatus, GCHandleType.Pinned)
arg_ptr = gh.AddrOfPinnedObject()
Console.WriteLine("arg_ptr before command01: {0}", arg_ptr.ToString)
retval_int = command01(hSerial, 1, arg_ptr)
Console.WriteLine("arg_ptr after command01: {0}", arg_ptr.ToString)
retval_ptr = New IntPtr(retval_int)
sStatus = CType(Marshal.PtrToStructure(arg_ptr, GetType(rc_status)), rc_status)
rc_sStatus = CType(Marshal.PtrToStructure(retval_ptr, GetType(rc_status)), rc_status)
Console.WriteLine("rc_sStatus:")
Console.WriteLine("status01 : {0}", rc_sStatus.status01.ToString)
Console.WriteLine("status02 : {0}", rc_sStatus.status02.ToString)
Console.WriteLine("status03 : {0}", rc_sStatus.status03.ToString)
Console.WriteLine("status04 : {0}", rc_sStatus.status04.ToString)
Console.WriteLine("sStatus:")
Console.WriteLine("status01 : {0}", sStatus.status01.ToString)
Console.WriteLine("status02 : {0}", sStatus.status02.ToString)
Console.WriteLine("status03 : {0}", sStatus.status03.ToString)
Console.WriteLine("status04 : {0}", sStatus.status04.ToString)
Debug.WriteLine("Error Code: " & Marshal.GetLastWin32Error)
End Function
//Debug prints:
arg_ptr before command01: 18494748
'WindowsApplication2.exe': 'c:\windows\assembly\gac\system.xml\1.0.3300.0__b77a5c561934e089\system.xml.dll' geladen, keine Symbole geladen.
arg_ptr after command01: 18494748
rc_sStatus:
status01 : 18494748
status02 : 1
status03 : 60368552
status04 : 1241784
sStatus:
status01 : 0
status02 : 0
status03 : 0
status04 : 0
Error Code: 0
//sign of life; debug-prints form the dll:
Hello Command01
mode: 1
Dumped sm_idle command code: 03 14 01 16
Dumped sm_idle answer code: 03 14 01 16
Das Programm "[996] WindowsApplication2.exe" wurde mit Code 0 (0x0) beendet.
I have a lot of functions like "command01" I need to use in the dll,
but "command01" ist the only func, with "rc_status" as return value.
Therefore the sStatus argument is much more important to me!
So Progload,
hope to hear from you, or other experts,
best regards,
Daniel
PS:
Prize is a bottle best, original beer from germany,
named "Tannenzäpfle"!
|
|
|
|
|
YuccaTree,
I don't see any reason you would have to pin the memory,
Give this a try,
Private Sub test(ByVal hSerial As Integer, ByVal iMode As Integer)
Dim retval As Integer
Dim sStatus As rc_status = New rc_status
Dim iSSize As Int32 = Marshal.SizeOf(sStatus)
Dim rStatus As IntPtr = Marshal.AllocHGlobal(iSSize)
'Marshal data from a managed object, to an
'unmanaged block of memory
Marshal.StructureToPtr(sStatus, rStatus, False)
' Call lc_command01
retval = lc_command01(hSerial, iMode, rStatus)
Debug.WriteLine("Error Code: " & Marshal.GetLastWin32Error())
'Marshal data from an unmanaged block of
'memory to a managed object.
Marshal.PtrToStructure(rStatus, sStatus)
'/// Do whatever with retval and sStatus here ---
Debug.WriteLine("status01: " & sStatus.status01)
Debug.WriteLine("status02: " & sStatus.status02)
Debug.WriteLine("status03: " & sStatus.status03)
Debug.WriteLine("status04: " & sStatus.status04)
'///---------------------------------------------
'Free the block of memory
Marshal.FreeHGlobal(rStatus)
End Sub
|
|
|
|
|
Hi,
tried the new code with the result:
Error Code: 0
status01: 0
status02: 0
status03: 0
status04: 0
Maybe it's because of the double pointer?
EXPORT struct rc_status *command01 (struct serialHandle *h, int mode, _ struct rc_status **status);
PS:
I had to build a class "rc_status" because
Marshal.PtrToStructure(rStatus, sStatus)
won't work:
< StructLayout(LayoutKind.Sequential)> _
Public Class rc_status
Private m_status01 As Integer
Private m_status02 As Integer
Private m_status03 As Integer
Private m_status04 As Integer
Property status01() As Integer
....
Property status02() As Integer
....
Property status03() As Integer
....
Property status04() As Integer
End Class
hope to hear from you,
best regards,
daniel
|
|
|
|
|
YuccaTree,
If anything should have worked building structure class should have, if you had it referenced ByRef, are you sure your .dll is exporting the values?
The only other thing can think of is allocating that memory as Task memory as it may be doing this:
Microsoft:
"Case of unmanaged method that expects pointer-to-pointer-to-structure. It expects the pointer to be passed in a stack, and that that pointer points to another pointer which is somewhere in memory. And that pointer actually points to actual structure. So these methods expect actually two levels of indirection. So in cases when a method expects two level of indirections there is again two options you can use. The first one, you declare a structure as a class, and then pass it by reference. Since managed class already contains one level of interaction using ref keyword will add additional level of indirection. So now you have two levels of indirection, which is exactly what unmanaged method expects."
"This looks fine, but there is one problem with this. This is related to memory manipulation I was talking about a little bit earlier, which is if this semantics of this third method is that it expects structure to be passed in, and then it will maybe free this memory, allocate new structure, and then point this pointer to newly allocated structure. There will be a problem unless unmanaged method works like that, so it uses co-task mem alloc and co-task mem free for allocation and de-allocation, because that’s exactly what intro marshaler is expecting."
Ref:
http://msdn.microsoft.com/msdntv/transcripts/20030424NETFXSKTranscript.aspx
I'm running out of ideas here, Is there any way for me to get the full code and that .dll via my email link?
progload
Send me an email via my link, I'll reply to it so you'll be able to send it to it.
-- modified at 12:46 Monday 13th February, 2006
|
|
|
|
|
My main form is undergoing a processes in Shell,
I have write a form, contains only a label for some words, before the shell run.
After the processes finish, form.close, form.dispose, form = nothing is seted.
However, I find the form doesn't shown the content, just like the application is hanging.
I have tried to using thread.sleep(2000), still like before but 2 seconds more long.
How can I show a "now loading" form when processing the shell command?
The reason that cannot use the msgbox is process on my main form will be stopped, so I cannot using msgbox, I just wanna send a text for the user, It is processing, need to wait.
|
|
|
|
|
Not sure if this is the best solution - (comments from others welcome) but you can show the Second form on a new thread:
Private Sub Button1_Click(ByVal sender ...EventArgs) Handles Button1.Click
Dim thrShowWait As New System.threading.Thread(AddressOf ShowSplashForm)
thrShowWait.Start()
'
'Execute your Shell commands here
'
thrShowWait.Abort()
thrShowWait = Nothing
End Sub
Private Sub ShowSplashForm()
Dim Splash As New frmSplash 'Form showing "Please Wait..."
'set frmSplash FormBorderStyle to 'None' so user cant close it
Splash.ShowDialog()
End Sub
|
|
|
|
|
You don't need a seperate thread if all your doing is putting up something like a messagebox. Keep in mind that this MessageBox form will NOT, and SHOULD NOT, launch your external app. All it's there for is to put up something for the user to look at. The form that creates and shows this MessageBox form should also be launching the external app.
Public Class myMessageBox
Inherits System.Windows.Forms.Form
Private Sub myMessageBox_Load(blah, blah) Handles blah
Label1.Text = "Loading...."
Me.TopMost = True
End Sub
End Class
' In your Form1 (or whatever you call it) code...
Dim myMB As New myMessageBox()
myMB.Show()
Application.DoEvents() ' This will make sure that your new messagebox will get painted
' Launch your external app here...
myMB.Dispose()
' Done!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I do it like this,
But the message form us just like hanging,
I mean the content of form is transparent.
How can I make it better.
|
|
|
|
|
Did you put the Application.DoEvents() line in BEFORE you launched your external app?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
Just for anyone else reading this thread, the Application.DoEvents() line was in the sample code I originally posted.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Wow, I got It!!
Thank you again!!
|
|
|
|
|
Hi I am making a windows service that monitors a folder and transfer the files created in that folder to another folder on the network.
I put the following in the OnStart routine:
xtr = New Xml.XmlTextReader("e:\setup.xml")
While xtr.Read
If xtr.NodeType = Xml.XmlNodeType.Element Then
If xtr.Name = "Target" Then
xtr.Read()
s_path = xtr.Value
ElseIf xtr.Name = "Dest" Then
xtr.Read()
d_path = xtr.Value
End If
End If
End While
I put the source folder to be monitored and the destination folder to copy to in the XML file, and set the value of s_path and d_path accordingly.
The problem is that when I start the service it just stop immediately. But if i set the value of s_path and d_path to something else before the first line of the above code, and set the values that correspond to the xml file when the above code run, the windows service start sucessfully.
The XML is created correctly cuz I have tested it with a VB Windows application with the same code as above. Does anyone know why that happen?
|
|
|
|
|
chiyinhk wrote: The problem is that when I start the service it just stop immediately.
Typically, a service is written to, on start, startup a seperate processing thread that continuously loops and looks for work to do. This has to be done as a seperate thread because if you put that looping code into the OnStart method of your service, there will never be a return from this method and the ServiceControl manager will think there is something wrong because it's waiting for a return code that it will never get.
In your case, you're just running a block of code that has an ending point and returns, something like the code you would put in a Load event in a Windows Forms app. You're not starting a thread to do the actual processing.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
How can I change reports and data sources for ReportViewer on runtime?
|
|
|
|
|
Hi All!,
I've a problem in copying files to a network computer using vb.net coding. I want to copy some files to another computer in a network(LAN). can anyone please tell me how to do this. the IP address of the network computer is 130.1.1.24.
thanx,
Prasant
|
|
|
|
|
Well, without knowing anything about the machine you want to copy files to, we can only guess at what you need to do. And DO NOT post IP addresses for your internal network in a public forum! This is a HUGE security breach and could get you fired!!!!!
What type of server is this machine you want to copy files to? Windows Server, Novell, Linux, FTP server, web server, ..., ???
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|