Contrast Algorithm C# Pointer To Marshal.copy

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


ADVERTISEMENT

VS 2008 AccessViolationException When Using Marshal.Copy

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

Marshal.Copy Error When Running Program, Complains About Protected Memory?

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

Copy From A Structure To Memory Pointer And Back?

Jun 12, 2009

How can I copy from a structure to the memory referenced to by a pointer back and forth?I need to do it with an offset.

Dim g_memoryPointer As IntPtr
Dim teArgs(10) as ArgumentStructure 'a structure defined somewhere outside my prog
Dim ix as Long, offset as Long

[code].....

View 5 Replies

VS 2008 Pointer - Error32'System.Reflection.Pointer' Has No Type Parameters And So Cannot Have Type Arguments

Jul 15, 2010

I have an open source project I converted to vb.net. I solved all the errors, except for one. This is the C# line

[Code]....

View 4 Replies

Implement An Algorithm Called "Diamond-Square Algorithm"?

Jun 8, 2009

I am trying to implement an Algorithm called "Diamond-Square Algorithm" I am having trouble ending it so that it retiurns the required result. So far I have the folloiwng.

[Code]...

View 3 Replies

Add An Option To A Program Of Enables "High Contrast" Mode In Windows XP?

Jul 20, 2009

I need to add an option to a program of mine that enables "High Contrast" mode in windows XP.

Just like the picture below, but programatically

View 4 Replies

C++ - Declare Pointer To Pointer In COM/ATL?

Dec 29, 2010

How can I declare pointer to pointer in ATL. Actually I have a handle which I want to pass by address to function. As shown below

STDMETHODIMP Function(HANDLE* hHC) //HANDLE declared as void * so actual type is void **

OR

STDMETHODIMP Function(LONG **hHC)

And want to access this function from the VB client.

View 1 Replies

USB Via .NET 2 Notifications And Marshal?

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

Marshal An Array With Fix Lenght?

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

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

Marshal Back To Main Thread?

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

Marshal Variable Length Array?

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

UI Marshal Class With INotifyProperty Changed?

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

VS 2010 Marshal.ReadInt32 -> AccessViolationException?

Jan 11, 2010

VS 2010 [RESOLVED] Marshal.ReadInt32 -> AccessViolationException

View 6 Replies

.net Equivilent Of Ruby's Marshal - Object Save/load?

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

Marshal Attributes To Be Passed As An Argument In This Declare Statement?

Sep 24, 2010

Marshal attributes to be passed as an argument in this Declare statement? [code]...

View 3 Replies

Office Automation :: Marshal.GetActiveObject Preventing Excel From Being Released?

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

Object Array To Byte Array - Marshal.AllocHGlobal Fragmentation Query?

Jun 14, 2011

I didn't think it fair to post a comment on Fredrik Mörk's answer in this 2 year old post, so I thought I'd just ask it as a new question instead..NB: This is not a critiscm of the answer in any way, I'm simply trying to understand this all before delving into memory management / the marshal class.

In that answer, the function GetByteArray allocates memory to each object within the given array, within a loop.Would the GetByteArray function on the aforementioned post have benefited at all from allocating memory for the total size of the provided array:

Dim arrayBufferPtr = Marshal.AllocHGlobal(Marshal.SizeOf(<arrayElement>) * <array>.Count)

I just wonder if allocating the memory, as shown in the answer, causes any kind of fragmentation? Assuming there may be fragmentation, would there be much of an impact to be concerned with? Would allocating the memory in the way I've shown force you to call IntPtr.ToInt## to obtain pointer offsets from the overall allocation pointer, and therefore force you to check the underlying architecture to ensure the correct method is used*1 or is there a better way? (ToInt32/ToInt64 depending on x86/64?)

*1 I read elsewhere that calling the wrong IntPtr.ToInt## will cause overflow exceptions. What I mean by that statement is would I use:

Dim anOffsetPtr As New IntPtr(arrayBufferPtr.ToInt## + (loopIndex * <arrayElementSize>))

I've read through a few articles on the VB.Net Marshal class and memory allocation; listed below, but if you know fo any other good articles I'm all ears![URL]..

View 1 Replies

VS 2005 What Can Use Instead Of A Pointer

May 1, 2010

I understand there are no pointers in VB.Net. I need to use something similar.The issue is that I have a structure that represent a deck of cards, with elements showing how many of each type of card there is. So I have my_deck.ace, my_deck.two, and so on.What I want to do is set a pointer called current_element that refers to any element in the structure. It may one time point to my_deck.three, and another time to my_deck.nine, and so on. It could point to any element.What I want to do is, for instance to set current_element to point to my_deck.ace, then decrementing current_element would reduce the count of aces by one.[code]that would work, but it's inelegant, I have about 30 different operations to perform, some of them using several lines of code. I'd like to avoid this if at all possible. I could tolerate doing it 2 or 3 times, but not 30.

View 8 Replies

Change The Pointer To Custom?

Oct 11, 2009

I need to change the default windows pointer to this: not generally, just in my program. (Form1) There's a Pointer Control But I Dont Know What That Does.

View 7 Replies

Compiled C Dll Can't Set Pointer When Called From ASP.NET App?

Dec 10, 2009

I've got a 3rd party C application that's compiled to a non-.NET non-COM DLL. It has one simple function declared like so: Declare Function CapiTaxRoutine Lib "taxcommono.dll" (ByVal sInData As String, ByVal OutputData As String, ByVal intINPutLength As Long) As Integer

If I place the taxcommono.dll in my path (C:WindowsSystem32 is what I'm using because it's what the vendor recommends),I can wire up a call to the function and it works just fine.It returns a 1 or 0 for success/failure, but it also sets the value of the OutputData string parameter (using some C pointer magic I'm not familiar with) to a huge fixed width format return record that has the data I need.When I call it from a .NET .exe application, it works just fine.When I try to call it from an ASP.NET application via a referenced compiled .NET wrapper DLL, it runs but can't set that string.In order to get it to run, I can't have taxcommono.dll in my path, but rather have to place it in my Bin directory of the web project.Does anyone know of a reason it can set the pointer when called from an .exe application but not when called from a web app?The .NET wrapper DLL I'm using works when called from our ERP software, which is not web based. But when I add a reference to that same DLL in the web app, it won't give me that output value.am used to just getting a return value instead of a function setting the value of one of my input parameters.

View 1 Replies

Create A Pointer To A Form?

Feb 10, 2010

In VB6 I have several child forms that have Subs and Controls with the same names.I need to access these Subs and Controls from public subs (in a module) that have a reference to the Active Form.[code]...

View 1 Replies

Create Pointer To Value Types?

Nov 12, 2010

I'm by no means a good programmer and I'm just trying to wrap my head around some of this stuff, so please forgive me if this is a dumb question.I want the following to produce a message box that says "2", not "5":

Public Class SomeClass
Private SomeInt As Integer = 5
Private SomeListOfInts As New List(Of Integer)

[code].....

View 1 Replies

How To Change The Cursor Pointer

Mar 30, 2009

im in a project using drag and drop events and.. , when i drag a label image, i need to change te cursor pointer from an image that is on a labelike the SO windows when you drag a file appears like a mirror with alfa minimun so its like the image but more transparent when i drag i need to change the cursor pointer from an image that i'm dragging by the way im, using visual studio .net and im programming in visual basic

View 6 Replies

How To Get The Function Pointer From Class

Nov 5, 2011

Public Class Form1 Public Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As IntPtr Public Declare Function GetProcAddress Lib "kernel32" Alias "GetProcAddress" (ByVal hModule As IntPtr, ByVal lpProcName As String) As IntPtr

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim hmod As IntPtr = GetModuleHandle(Nothing) 'Work Dim addrs As IntPtr = GetProcAddress(hmod , "TestFunction") 'Not work, always NULL why??

View 3 Replies

Mouse Pointer As Icon?

Feb 20, 2012

How do I change my mouse cursor/icon to use a image or icon. I want to make a simple "wack a mole" type game but I dont know how to change the pointer to a icon or at least get a image to follow the pointer.

View 7 Replies

Object Properties Via Pointer?

Feb 23, 2010

I have a form that has 100 text boxes with 100 coinciding labels. I want them hidden until another function populates the text boxes with data gathered elsewhere. The data could be between 1 and 100.

I would like one loop where I can assign the data to the correct text box, set it visible and set the label visible. I can not figure out how to do this in VB, or know if it is even possible.

Here is an example of what I would like to do

Dim i As Long = 1
Dim textbox As String = "textbox"

[code]....

I would also like to do this to hide all the items on the form in the on load event.

View 16 Replies

Passing A Pointer To A Structure To A C DLL?

Sep 28, 2010

Private Declare Function src_simple Lib "libsamplerate.dll" (ByVal data As IntPtr, ByVal converter_type As Integer, ByVal channels As Integer) As Integer<br/>
Private Declare Function src_strerror Lib "libsamplerate.dll" (ByVal err As Integer) As IntPtr<br/>
<br/>
<StructLayout(LayoutKind.Sequential, Pack:=1)> _

[code]....

View 1 Replies

Pointer - Rewrite A C++ Library

Jan 4, 2012

I'm trying to rewrite a C++ library. But I have an issue. I'm not extremely pointer-savvy. In the C++ class there is a std::vector that holds unsigned int pointers (vector<unsigned int*>), and the int pointer just points to an array of integer data.

Here is the C++ code I'm a bit unsure about:

unsigned int* relocation = m_relocations.front();
m_relocations.pop();
unsigned int* reloc = *(unsigned int **)relocation;

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved