I have an already developed C# application, that needs to pass a pointer to
an array of bytes (of size 50), to another already developed C++ application
hosted in a DLL. My array of bytes are hosted in an unsafe static class to
force the C# garbage collector not to move it around, as the C++ application
will be responsible to update the array during runtime. My structure is
defined as follows:
[StructLayout(La youtKind.Sequen tial)]
public struct DATA
{
[MarshalAs(Unman agedType.ByValA rray, SizeConst=50)]
public statis byte[] myArray;
}
I attempt to pass the reference of the array to the C++ application in the
following manner:
fixed (byte *address = &MyStaticClass. DATA.myArray[0])
{
MyApplication.S etArrayReferenc e(address);
}
Now, when I attempt to pass a reference to this array to the C++ application
(see insert above), the following exception occurs:
System.NullRefe renceException >> "Object reference not set to an instance of
an object.". Any idea what I am doing wrong, and how this can be solved?
Regards
Nico Gerber 3 1565
"Nico Gerber" <ng*****@telkom sa.net> wrote in message
news:cl******** **@ctb-nnrp2.saix.net. .. Now, when I attempt to pass a reference to this array to the C++
application (see insert above), the following exception occurs: System.NullRefe renceException >> "Object reference not set to an instance
of an object.". Any idea what I am doing wrong, and how this can be solved?
Has you array been created using new or some other method? If that's not the
problem, what is null and on what error does the line occur. What is your
declare statement for the API call?
myArray = new byte[50];
Michael Culley
My problem is that the array should actually 'live' inside the structure ...
by calling the 'new' operator I understand that the memory is allocated on
the heap somewhere, with only a reference to it from the structure? Are
there any way to ensure that the allocated memory is actually 'inside' the
structure?
"Michael Culley" <mc*****@NOSPAM optushome.com.a u> wrote in message
news:#q******** ******@TK2MSFTN GP10.phx.gbl... "Nico Gerber" <ng*****@telkom sa.net> wrote in message news:cl******** **@ctb-nnrp2.saix.net. .. Now, when I attempt to pass a reference to this array to the C++ application (see insert above), the following exception occurs: System.NullRefe renceException >> "Object reference not set to an
instance of an object.". Any idea what I am doing wrong, and how this can be solved? Has you array been created using new or some other method? If that's not
the problem, what is null and on what error does the line occur. What is your declare statement for the API call?
myArray = new byte[50];
Michael Culley
"Nico Gerber" <ng*****@telkom sa.net> wrote in message
news:cl******** **@ctb-nnrp2.saix.net. .. My problem is that the array should actually 'live' inside the structure
.... by calling the 'new' operator I understand that the memory is allocated on the heap somewhere, with only a reference to it from the structure? Are there any way to ensure that the allocated memory is actually 'inside' the structure?
Not sure about that one. If it's only a few elements in the array you could
declare them all as Value1, Value2 etc but that would be cumbersome over a
cerain size. You could play around with the FieldOffset attribute and the
StructLayout attribute. I'm not sure what happens if you leave a hole in
your struct, maybe that memory is free to use, eg
[StructLayout(La youtKind.Explic it)]
private struct ABC
{
int SomeValue;
[FieldOffset(4)]
byte x;//this will be the array
[FieldOffset(100 )]
int SomeOtherValue;
}
Michael Culley This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: xcomm |
last post by:
Hi All,
<?php
$vars= array("_SERVER","_SERVER","_SERVER","_SERVER","_SERVER","_SERVER");
foreach($vars as $var) {
if(isset($$var))echo("$var: ${$var}<br>\n");
}
?>
php.net:
|
by: student |
last post by:
while compiling on:
SunOS 5.8 Generic_108528-27 sun4u sparc SUNW,Sun-Fire-280R
I get the following error:
Undefined first referenced
symbol in file
matrixi_ tst.o
ld: fatal: Symbol referencing errors. No output written to a.out
|
by: sreddy |
last post by:
I am trying to write a sql query on self referencing table.
Just to brief ..Database is related to a Hiring department of the
Qwest company.
I need to generate a Report used by in HR department to pay the
employees
who have referred the candidates for the jobs in their
..
This report is used by the HR department to get the required
|
by: Simon |
last post by:
Am using the following code.
<script language="JavaScript1.2">
function setquantity(productindex,productquantity)
{
//create the reference object
irefname_none = eval("document." + productindex + "none");
<snip>
|
by: jstaggs39 |
last post by:
I want to create a Dcount and an If...Then...Else statement to count
the number of records in a table based on the date that is entered to
run the form. The If....Else statment comes in because if the amount of
records for a particular date is positive, i want the form to stop
running, if there are no records that contain the date in question,
then it should continue to run the form. The problem i'm having is
referencing the date that is...
| |
by: Mikey_Doc |
last post by:
Hi
We are running cms 2002, Framework 1.0 with Visual studio 2002. We
have just upgraded to Framework 1.1 and visual studio 2003.
All of our database connection strings are stored within the machine
config, this was necessary as our web site has 4 environments and the
database server has a different name in each.
Since the upgrade the applications can't read the strings in the
|
by: gary |
last post by:
Hi,
I am trying to reference an anchor in a user control with a url. This
worked in 1.1 but no longer works in 2.0.
The ascx control is located in a "/include" folder
If you have a hyperlink control and you assign the navigateurl property =
"../#anchor" whereby you want to add this # reference to the current url the
url ends up with the #anchor twice.
|
by: Brett Romero |
last post by:
Say I have a library (A.dll) with a method that accepts a collection of
a specific type. The type is defined in B.dll. In A.dll, I need to
loop through this collection and reference fields of the type.
For example, a Person type. It may have arm, leg, feet, and hands.
Hands is a collection containing types of fingers. The only way to get
at fingers is by accepting the parameter as its true type. This means
I'll need a file...
|
by: Tim F |
last post by:
Problem: I'm receiving the error "File or assembly name XXXXX or one of its
dependencies, was not found." when trying to execute code in an assmebly that
has both a strong-name and has been installed into the GAC.
We originally had this assembly without a strong-name and we were
successfully using it by referencing it when it was NOT in the GAC. The
assembly was built using the 1.0 framework and we were able to call it from
both 1.0...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |