|
One of the arguments that I must pass to the Function in a DLL is a pointer to an array of a structure that has a byte array in the middle of the structure with a fixed length of 256 bytes. Here is the Structure:
<StructLayout(LayoutKind.Sequential)> _<br />
Public Structure KEYBOARDINFO <br />
Public KeyboardID As Int32<br />
Public KbdName(0 To 255) As Byte<br />
Public pKeyboard As Int32<br />
End Structure
My problem is I cannot get VB to make this structure be sequential in memory since it has the KbdName(255) in the middle of it. I have tried everything I can think of and VB always puts KbdName at the end. How can I get it to be sequential, so I can pass it to the function as an argument.
Rand
|
|
|
|
|
Try applying the following attribute to your structure...
<br />
< StructLayout(LayoutKind.Sequential) > _<br />
Public Structure KEYBOARDINFO <br />
Public KeyboardID As Int32<br />
Public KbdName(0 To 255) As Byte<br />
Public pKeyboard As Int32<br />
End Structure<br />
[Edit]
Oops. This website took out the attribute in the above code on my 1st post. It should show up for you now.
[/Edit]
-- modified at 13:09 Monday 7th November, 2005
|
|
|
|
|
Thanks, but I already did that. I had it in the code I posted, but the website took it out of my code. It does not work. It makes the structure sequential except for it puts the array at the end, not in the middle where it must be.
Any other ideas?
Rand
|
|
|
|
|
How about this?
<br />
< StructLayout(LayoutKind.Explicit) > _<br />
Public Structure KEYBOARDINFO <br />
< FieldOffset(0) > Public KeyboardID As Int32<br />
< FieldOffset(4) > Public KbdName(0 To 255) As Byte<br />
< FieldOffset(260) > Public pKeyboard As Int32<br />
End Structure<br />
-- modified at 13:43 Monday 7th November, 2005
|
|
|
|
|
Thanks, but this does not work either. Again the array is always put at the end of the structure. In VB.NET you actually cannot define a fixed size array in a structure, so what I have been trying is one of these formats:
< StructLayout(LayoutKind.Sequential) > _
Public Structure KEYBOARDINFO
Public KeyboardID As Int32
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=256)> Public KbdName As Byte()
Public pKeyboard As Int32
End Structure
or else this format:
< StructLayout(LayoutKind.Sequential) > _
Public Structure KEYBOARDINFO
Public KeyboardID As Int32
Public KbdName As Byte()
Public pKeyboard As Int32
End Structure
Then redim KbdName to 256 byes
Is there another way to get a fixed length array in a structure? Doing it either of these two ways I guess that VB thinks the size of the array will change, so it always forces it to the end of the structure in memory so there is room to grow.
Any more ideas?
Rand
-- modified at 14:22 Monday 7th November, 2005
|
|
|
|
|
rand19 wrote: Is there another way to get a fixed length array in a structure?
There is the VBFixedArray attribute, but it doesn't actually allocate anything. It seems to only indicate to API calls that it should be treated as a fixed array. Might be worth a try.
The thing is, an array is a reference type, not a value type. It'll never take up 256 bytes in the structure itself (in the stack). You might have to play around with marshalling to make this work.
|
|
|
|
|
I'm creating a component in VB.NET which acts as kind of a wrapper for Ms Outlook 2003 and Ms Word 2003. There are three components which can be used seperately. Now when I want to use the Outlook component, I don't want to load the Word assemblies and vice versa, but I dot want the controls within a single assembly.
Is it possibly to create the references to the required Office Interop Assemblies at runtime (in the constructors for example) so when loading my assembly, not needed office resources will be left alone?
For example, when using the Outlook control, my assembly loads Office.Core.dll and Office.Outlook.dll and NOT Office.Word.dll
I love it when a plan comes together
|
|
|
|
|
Did you try using classes in the System.Reflection[^] namespace? They allow you to load assemblies at runtime, which is exactly what you want to do.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
The previous reply hits it on the head, but be warned that if you use Word as the Outlook email editor, it will load Word components regardless.
...Steve
|
|
|
|
|
I was hoping to be able to use multiple selection upon a dropdownlist but the only info i have found is related to a dropdownlist in a datagrid. Is it possible then just to add the multiple selection to a dropdownlist the same way as when using the datagrid. thank you
gfhg
|
|
|
|
|
Dropdownlists are meant to allow user to select a single value. What you could do is cheat a little bit by displaying a ListBox on top of your combobox. To do that, capture the combobox dropdown event then call SuspendLayout of combobox, place dropdownlist on top, and call ResumeLayout of your combobox. When user is done selecting, hide the listbox.
|
|
|
|
|
Hi, I am tejaswi and having a small doubt in VB regarding the collections class.
The following code Is not working
Dim temp as new clsParameterDetail
Dim objcoll as new collection
Temp.initializeobj()
Objcoll.add( temp)
Where as if I declare it as an array ( dim temp() as new clsParameterDetail )
And after redimensioning and initializing the temp array,
It is accepting the statement (Objcoll.add(temp) )
What is the difference between an array and normal object. In case of a single object the .add is not working( giving a message like ‘property or method is not supported’) where as in case array it is accepting.
It is not even accepting sth like objcoll.add(temp(parameterCount))
but it is accepting for strings even if it is not an array .
Please clarify my count.
And one more thing is – Is CType(obj,TypeName) a function available in visulbasic or only .net ? if in vb any references to be added , this function is not available here in vb here.here if i type vba. ,all are coking like cstr e.t.c but ctype i snot coming.
|
|
|
|
|
Hi, I am tejaswi and having a small doubt in VB regarding the collections class.
The following code Is not working
Dim temp as new clsParameterDetail
Dim objcoll as new collection
Temp.initializeobj()
Objcoll.add( temp)
Where as if I declare it as an array ( dim temp() as new clsParameterDetail )
And after redimensioning and initializing the temp array,
It is accepting the statement (Objcoll.add(temp) )
What is the difference between an array and normal object. In case of a single object the .add is not working( giving a message like ‘property or method is not supported’) where as in case array it is accepting.
It is not even accepting sth like objcoll.add(temp(parameterCount))
Please clarify my count.
And one more thing is – Is CType(obj,TypeName) a function available in visulbasic or only .net ? if in vb any references to be added , this function is not available here in vb here.here if i type vba. ,all are coking like cstr e.t.c but ctype i snot coming.
|
|
|
|
|
I am designing a windows app in vb.net. There I added a imagelist control which contains some alphablended images. When I try to debug it it shows an error
"An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
Additional information: Exception has been thrown by the target of an invocation."
pointing the line
" Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)".
But while there was no images in Imagelist control nothing happened.
What is the wrong with it? What should I do now?
Thank you in advance.
Anindya Chatterjee
|
|
|
|
|
hi all
well i m fresher in vb.net.i have prob in vb.net.
problem - how to decice client server applicion architecture.whether to use single application or two application(one for server and one for client) and how they communicate between each other.
thanks
sahil
|
|
|
|
|
I'm using HelpProvider to display a chm file on the users machine. When I view the properties of the HelpProvider, I want to specify the location of the chm file in HelpNameSpace. The chm file is written to the users application file. By default (i.e., provided the user doesn't change the install location), I know where the chm file will be (e.g., C:/Program Files/[program folder]/[filename].chm)so I can specify it in HelpNameSpace. But what if the user chooses not to install in the default location? I was hoping that the browser for HelpNameSpace would be similar to the Icon browser and would let me specify a file saved in the target application folder... but it doesn't. Can someone help?
|
|
|
|
|
Can't you use the Application's StartupPath property and set the path to the CHM file at runtime?
System.Windows.Forms.Application.StartupPath
I love it when a plan comes together
|
|
|
|
|
Hmmm... looks promising! So you're suggesting I query for Application.StartupPath and append the path to the file name of the CHMs in the application folder?
Thank you very much!
David
|
|
|
|
|
Worked like a charm! Thank you so much.
|
|
|
|
|
First I'd like to say that I've been trying to find a solution for 2 days from many resources. The code runs but only the first item in the listbox is being killed.
My textfile = "list.txt"
Contents of list.txt
notepad
wordpad
Here is a snipit of the main section of my code.
<br />
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
'Opens File Specified as .txt only<br />
Dim openFile As New System.Windows.Forms.OpenFileDialog<br />
openFile.DefaultExt = "txt"<br />
openFile.Filter = "Text documents (*.txt)|*.txt"<br />
openFile.ShowDialog()<br />
If openFile.FileNames.Length > 0 Then<br />
Dim filename As String<br />
For Each filename In openFile.FileNames<br />
' Displays path of text file to listBox1<br />
ListBox1.Items.Add(filename)<br />
'Displays content of selected text file to listBox2<br />
Dim file As New System.IO.StreamReader(filename)<br />
Dim oneLine As String<br />
oneLine = file.ReadLine()<br />
While (oneLine <> "")<br />
ListBox2.Items.Add(oneLine)<br />
oneLine = file.ReadLine()<br />
End While<br />
file.Close()<br />
Next<br />
End If<br />
End Sub<br />
Public Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click<br />
'Checks to check if items in listbox2 are selected<br />
Dim n As String<br />
n = ListBox2.Text<br />
If n = "" Then MsgBox("No Process Selected!", MsgBoxStyle.Information, "Process Not Selected")<br />
'Compares items in textbox2 against running processes, if found it kills it<br />
Dim lined As String<br />
Dim proc() As Process<br />
Dim i As Integer<br />
Dim prokill As Boolean<br />
lined = (ListBox2.Text)<br />
proc = Diagnostics.Process.GetProcesses<br />
For i = 0 To proc.Length - 1<br />
If proc(i).ProcessName = lined Then<br />
Try<br />
proc(i).Kill()<br />
prokill = True<br />
Catch ex As Exception<br />
Exit Sub<br />
End Try<br />
End If<br />
Next i<br />
<br />
'removes killed processes from listbox2<br />
ListBox2.Items.Remove(ListBox2.Text)<br />
ListBox2.SelectedIndex = -1<br />
'ListBox2.Items.Clear()<br />
End Sub<br />
I've tried adding listbox2.text to a database, but my research and small amount of experience leave me with a headache for 2 days... any help or guidance would be greatly appreiciated. Thanks.
|
|
|
|
|
r00tb0x wrote: lined = (ListBox2.Text)
proc = Diagnostics.Process.GetProcesses
For i = 0 To proc.Length - 1
If proc(i).ProcessName = lined Then
Try
proc(i).Kill()
prokill = True
Catch ex As Exception
Exit Sub
End Try
End If
You need to replace the code that takes the text from the listbox, and replace it with code which iterates through the Items property, using foreach. Then you can process each one. I'd create a KillProcess method, and call it from the loop, just to factor out the code a little.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I'm not sure how I would go about that. I appologize, I started learning about 4 days ago. I've had to research each section of my program and this is what I've been stuck at for 2 days. If you could maybe start me off where I need to go with it. I can run it through my head, but of course that's not how it works.. lol. Thanks again Christian...
|
|
|
|
|
Something like this:
Dim lined As String<br />
<br />
For Each lined In ListBox1.Items<br />
proc = Diagnostics.Process.GetProcesses<br />
For i = 0 To proc.Length - 1<br />
If proc(i).ProcessName = lined Then<br />
Try<br />
proc(i).Kill()<br />
prokill = True<br />
Catch ex As Exception<br />
Exit Sub<br />
End Try<br />
End If<br />
<br />
Next<br />
Next
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Well I swear I tried something similar... anyhow, I thank you again! Another simple solution to a silly problem. Thanks.
|
|
|
|
|
Glad to help. I have to admit, I did not test this, but there's no reason I can see for it not to work. I typed it into the IDE, so the code itself is valid and should be correct. It's certainly how it's done, even if there's some change needed to make it work.
Christian Graus - Microsoft MVP - C++
|
|
|
|