C++ - Why Do C# And VB.NET Implicitly Marshal Char* Differently
May 22, 2010
What is the most timers you have used in an application? I think the most I have ever used is 2.In another forum this question was asked. "I have a Timer ... I have a situation where I want to run the code in the Tick event ONLY ONCE not on the interval i have the timer set too."
I responded with Timer1_Tick(New Object, New System.EventArgs) Which led to this "The 'sender' object is VERY important when you have more than one Timer being handled by the Tick event procedure. This is because in a multi-timer tick event procedure, the only way your program knows which timer just fired is by querying the 'sender' object.When you use code like this you are putting nothing into the 'sender' object, so that if you were ever going to query it a 'kaboom' is going to happen.""...this 9 timer Tick event handler job done. Remember, all that is required is the correct timer name gets put into the ListBox." "The need for multi-timers to be handled by a single Tick event handler happens all the time. How would a real life programmer handle this? "Oh, to test the "kaboom" theory I wrote this and ran it overnight successfully:
[code]...
View 33 Replies
ADVERTISEMENT
Dec 16, 2008
i want to read a character 1 by 1 from a string and a .txt, i know all about stream reader so for the .txt would it be somthing like:textbox1.text = tr.readCharacter.i would prefer to be able to read from a textbox or String array though.
View 10 Replies
Mar 30, 2012
I need validation for string to comply with next: no space char starts with one delimiter char ends with one delimiter char has no other char as delimiter char. Updated sorry missed that should only be one delimiter char at start and at the end
View 2 Replies
Sep 30, 2010
Public Shared Function UrlTokenDecode(ByVal input As String) As Byte()
If (input Is Nothing) Then
Throw New ArgumentNullException("input")[code].....
View 3 Replies
Mar 7, 2009
Cannot implicitly convert type 'decimal' to 'int'. An explicit conversion exists
View 1 Replies
Jul 12, 2011
I am calling a GetSerialNo function But it showing some error like:
Cannot implicitly convert type 'decimal' to 'int'. An explicit conversion exists (are you missing a cast?).
Here is the code:
CODE:
View 3 Replies
May 19, 2009
i am trying to increment a char in vb.net, eg: Dim letter As Char = "a"c. and i want to make it b, and so on. how can i do this?
View 1 Replies
Jan 14, 2009
I'm a VB6 programmer who was forced to upgrade to Visual Studio 2005 Version 8.0.50727.42 .NET Framework Version 2.0.50727. I am trying to write a call-back which will intercept a Windows message for when our USB HID device is plugged or unplugged. We have a custom .dll which handles the majority of the HID interface. I just need to call a few API's to connect to the device. I can connect and communicate.
I am looking at USB Complete Third Edition. The code examples do not compile. I'm unsure if this is because of the .NET version 2 or the 2005 dialog of VB. I cannot resolve "StructLayout..." statements, but the program appears to be working without them. I cannot get any "Marshal." statements to compile, which is where I am finding it difficult to get around.
[Code]...
Although OnDeviceChange() is being called six times, both IF statements fail. m.msg is 0x219, which is Device Change. m.WParm is always 7, m.lParm is always 0. And, this is where I'm stuck. m.lParm should be a pointer which gets me to the device path? Don't know what 7 is.
So, maybe I'm not registered to receive the proper messages from the device (or I'm looking in the wrong place). The missing step might be to call the RegisterDeviceNotification() API. This book is telling me to use frmMy.Handle declared globally as Friend frmMy As frmUSB - that gives me a null reference runtime error, so I swapped in Me.Handle for the first parameter to RegisterDeviceNotification(). It likes that. But, then it has heartburn with the buffer pointer - not so easy to resolve in Visual Basic. The call wants a LONG. I have DevBroadcastDeviceInterfaceBuffer, which the book says to use Marshal.AllocHGlobal(Size) and Size is Marshal.Sizeof(DevBroadcastDeviceInterface). Neither Marshal statement compiles and I'm not sure if it was removed in this version of .NET? Anyone? I really don't need a dynamically allocated buffer. This is quickie VB app for a single USB device.
Can anyone tell me how far down the rabbit hole I am and what I'm missing. I can tell when something changes to some USB device. I have a handle to that device supplied to me by a custom API library - probably is the HID handle.
How can I setup to receive a message when my HID USB device is unplugged or plugged in?
View 6 Replies
Feb 20, 2012
I need an array with fix String lenghts and fix rows... I do this...
Imports System.Runtime.InteropServices
Public Class Class1
Public WPFFunktion As String
[code]....
View 1 Replies
Dec 15, 2009
I am using a COM library in my VB.NET app that has an asynchronous execution method and signals my application via an event when it completes. The event handler is on a different thread from the calling thread. I want to invoke another execution on the main thread when I receive the completion event. If I call directly in the event handler for another execution it starts on the new thread. How do I marshal back to the main thread. This is done in a dll not in a form.
View 3 Replies
Jun 8, 2010
I'm trying to call the GetInterfaceInfo Windows API - it accepts a structure as one of its parameters and this structure has a member that is an array. The API populates the contents of the array when it is called and there can be any number of items in the array. How can I define such an array in my structure?
If I just use a normal .NET array like so then the program just crashes (no exception thrown)
<StructLayoutAttribute(LayoutKind.Sequential)> _
Public Structure IP_INTERFACE_INFO
Public NumAdapters As Integer
[Code]...
and this works fine, but the problem is I have to define the SizeConst attribute as you can see to something large (64 in this example) so that the API doesnt fail because the array wasnt big enough. Firstly this is a waste of memory as in most cases the number of items the API sticks in the array will be less than 10, but secondly if there was ever a case where the API wanted to put more than 64 items in then it would fail.
Using ReDim to set the length of the array at runtime seems to have no effect, and that SizeConst attribute has to be set to a constant value so there's no way I can dynamically set it.
View 8 Replies
Jan 24, 2010
creating a business layer in a .dll which at the moment is being used on a windows forms application. I have some objects with properties that use iNotifyPropertyChanged to update the UI which has all been working fine. My problem is tarted to explore using multiple threads and ing a cross-thread error because the properties are being changed on a different thread to the UI and iNotifyPropertyChanged is attempting to update the values (shown in labels) on the UI thread... shows the best way to solve my problem. The .dll will never know what Forms application is using it so I really dt want to hard code references into the objects. From what I gather this code allows you to register a form with the .dll and then add the invoke to OnPropertyChanged to avoid any threading issues. Is this correct?
View 5 Replies
Dec 24, 2010
I get an AccessViolationException using this code (attempted to access protected memory, this is often an indication that other memory is corrupt) on the line in DoWaitNotify that copies the pixel data back to the location in memory. In my experience, that usually means that the array is too large, but it all seems to check out. Does image data expire after a certain time or something?
Public Class Form1
Private Const NUM_THREADS As Integer = 3
Private Original As Bitmap
[Code]....
View 4 Replies
Jan 11, 2010
VS 2010 [RESOLVED] Marshal.ReadInt32 -> AccessViolationException
View 6 Replies
Mar 22, 2012
I have split a string into a char array, now i need to copy the char array to an int array with the ASCII values of each char.Donīt know how to do it without looping each value.
This is my code:
origen = RichTextBox1.Text.ToString
Dim valor As Char() = origen.ToCharArray
Dim numeros As Integer() = (How can i convert "valor" to an int array?????)
View 10 Replies
Apr 28, 2012
I tried to translate this code to vb.net using Marshal.copy but I can't get it to work
for (int y = 0; y < bitmapdata.Height; y++)
{
byte* destPixels = (byte*)bitmapdata.Scan0 + (y * bitmapdata.Stride);
[Code]...
View 1 Replies
Sep 18, 2009
VB Code:
Private Sub MDIForm_Load()
Dim tzinfo As TIME_ZONE_INFORMATION
Dim lResult As Long
[Code]...
Error Message "Cannot implicitly convert type 'System.TimeZone' to 'int'"
View 4 Replies
Oct 4, 2010
I've been working on learning VB.Net from VB6 and for some reason when I use On Error Goto handlers, or On Error Resume Next the program still procs an exception and ask to continue or close.I don't really understand what I am missing, everything I've read said it's the same as VB6 with a few extra options.
View 9 Replies
Jun 8, 2011
When I view images on my development PC they look fine, but when I view them on other PC's, the images are sized differently and often get cut off. I've tested this on multiple PC's and the images always get cut off.I've attached the images from my PC and another PC to this post, the image that is cut off if from a Windows XP PC.I'm using VS 2010 on Windows 7 64-bit.
View 7 Replies
Jun 20, 2012
I'm just needing a simple bit of code for vb.net that will allow me to marshal an object into a string, allowing for the saving and loading of this string so I can save my classes, needs to be simple and easy!
View 1 Replies
Sep 24, 2010
Marshal attributes to be passed as an argument in this Declare statement? [code]...
View 3 Replies
Jun 5, 2009
i have found [char] specified in some of the examples at msdn , what is the difference between char and [char]
View 2 Replies
Jul 4, 2009
I have a web application that works in our stage/test environment fine but once we moved it to our production environment something weird happens. All the control ids change. a label went from ctl00_cphMainContent_lblPetName to _ctl0_cphMainContent_lblPetName. Why would this happen? What could cause something like this to happen. The only two differences I know of are the production environment has HTTPS and I've disabled debugging.
View 3 Replies
Apr 5, 2011
I'm working on a website that creates pdfs dynamically.I've been playing around with two different pdf controls- wpcubed and abcpdf, and was surprised to see that they both appear to render text differently.
wpCubed:
abcpdf:
They are both using arial 25pt bold, so I was expecting them to look identical. Can anyone explain why they don't. Here are the full files: wpCubed , abcpdf
View 1 Replies
Sep 4, 2011
msgbox(System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList(0).ToString())
is showing Ip address in Win XP but in Windows 7 it is not showing.
View 7 Replies
Dec 23, 2009
If you create new projects in C# and VB.NET, then go directly in the Immediate Window and type this:
? 567 / 1000
C# will return 0, while VB.NET will return 0.567.To get the same result in C#, you need to type
? 567 / 1000.0
Why is there this difference? Why does C# require the explicit decimal point after 1000?
View 5 Replies
May 17, 2010
I've created a simple Windows Forms Application and the idea is I want to identify all instances of Excel, save any open workbooks to my desktop and close all the Excel instances down.[code]I'm pretty new to this C# business so hints on the following two possible issues I've identified would be much appreciated:The ForEach loop doesn't seem to be successfully looping through the XlApp.Workbooks collection as I was hoping.
It seems that I can't quit each Excel application which, with my current code structure, is causing an infinite loop. My suspicion is that Marshal.GetActiveObject() is locking it up and preventing it from closing?If nothing obvious jumps out then I might try the alternative method by Andrew Whitechapel mentioned and linked to on this thread.
View 11 Replies
Dec 5, 2010
I get this error on this line: System.Runtime.InteropServices.Marshal.Copy _
(Scan0, Data2, 0, Data2.Length)
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I also sometimes get an error on this line:
Dim dc1 As IntPtr = CreateDC("DISPLAY", Nothing, Nothing, CType(Nothing, IntPtr))
What I'm trying to do is take a screenshot and then read the colors of pixels. I currently have a working vb.net copyfromscreen method but it's SLOW and using 100% cpu usage.
[Code]...
View 3 Replies
Dec 30, 2009
Example:
Dim Sh32 As Object = CreateObject("Shell.Application")
Dim path As String = "C: empcatalog.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: empcatalog.zip"
Dim sf As Object = Sh32.NameSpace(path.ToString)
Clearly path = path.ToString, but they behave differently when used as COM parameters.
View 1 Replies
Feb 25, 2011
I have a datagridview I am displaying on a form and would like to format one of the columns differently then the available formats. I have a column that is a decimal(18,2) (in the table) named "MyDecimalField". In asp.net I could do this, in the "template field" of a datagrid.
math.round(MyDecimalField / 60 , 2)
In VB.net forms I cant figure out how to do that. Basically I need to divide the cell by 60 and round that to 2 decimal places.
IE
the Cell contains this: 1283.93
I want the user to see this: 21.40
1283.93 / 60 = 21.3988333 then round it to 21.40
View 1 Replies