Display value of a structure or member variable

G

Guest

I have a class library project that uses unmanaged C dll to perform some
image handling. This DLL requires me to pass in a structure containing image
coordinates. In VB6, I could use a type/endtype and define left, top, right,
and bottom coordinates. In .NET, I can use a structure to do the same thing.

In .NET only, I have found odd behavior in my C DLL, so in debugging, I try
to view the values of my 4 public variables in my structure. I do this
BEFORE I pass the structure to the C DLL. The values of the member variables
are not the values I assigned them. In fact, I execute a line like this:

struct.top = intVariable

then, after executing this line, I try to display the value of this
variable. All member variables behave the same - they all evaluate to zero.

If I attempt to execute this same line in the debugger, I get a debugger
error:

System Error &H80131303&

If I write a test application (standalong EXE), I do not see this behavior.

Is there anything I can do to find out if my C dll is getting nothing but
"0" ?

Is there something about the system error that's causing this problem?

In researching this system error, I found it's about a core class that's not
loaded, although it doesn't say what class. My class library is being loaded
late-bound, and I'm using reflection to load the DLL into memory. Is this
related?

thanks,
andrew
 
M

Mattias Sjögren

Can you post relevant parts of your code (like the native structure
definition and your corresponding VB version)?


Mattias
 
G

Guest

Hi,

Sorry for the delay...

This is the structure:
Public Structure RTKRECT
Public left As Short
Public top As Short
Public right As Short
Public bottom As Short
End Structure


this is the intialization:
MyFunct(
ByVal lAbsLeft As UInt16, _
ByVal lAbsTop As UInt16, _
ByVal lAbsRight As UInt16, _
ByVal lAbsBottom As UInt16, _
....)

Dim rectCrop As New RTKRECT

And this is how I set up the variables:

'TODO: fix when setting these values when at coordinates
1100,0,1300,100 causes all to be "0"
rectCrop.left = lAbsLeft
rectCrop.top = lAbsTop
rectCrop.right = lAbsRight
rectCrop.bottom = lAbsBottom


I have additional information I didn't have before:

When the structure is defined such that the member variables are of type
"Short" then there is no problem to report - everything works as expected,
even if the local variables are uint16, int16, ushort, or short.

when I declare the structure's member variables as either "UShort" or
"Int16" or "UInt16" then I see the problem. It seems that the UInt and Int16
are not fully CLR-compliant data types, which might explain the behavior.
However, UShort is CLR-compliant, and therefore does not explain the behavior.

FYI - I am lucky in that the rect structure (image coordinates) can be
passed to a C-library when I use SHORT as long as my coordinates do not
exceed 32767, even though the library expects unsigned data types.

I suspect that other people who need to provide data outside this range must
pass in negative numbers to get to the range +32768 to +65535?

It makes no difference if I use the "New" keyword for initializing the
structure.

I cannot reproduce the problem in any combination of conditions if I test
inside a standalone windows application, but in my application, the code
resides in a class library who is loaded late-bound using reflection. Not
sure if this is relevant, but might explain behavior between standalone exe
and dll.

aj
 
M

Mattias Sjögren

When the structure is defined such that the member variables are of type
"Short" then there is no problem to report - everything works as expected,
even if the local variables are uint16, int16, ushort, or short.

when I declare the structure's member variables as either "UShort" or
"Int16" or "UInt16" then I see the problem. It seems that the UInt and Int16
are not fully CLR-compliant data types, which might explain the behavior.
However, UShort is CLR-compliant, and therefore does not explain the behavior.

Well your problem sounds more and more strange. Short and Int16 are
the exact same types (Short is just a VB alias keyword for Int16), so
there should be no difference whatsoever in behavior.

But unless you can post a short sample application that will let us
reproduce the problem, I don't think I can be of much help.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top