*****************************************
* *
* TestUDTPassing VB.NET source code *
* *
*****************************************
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.ArgumentException
Module TestUDTPassing
Sub Main()
Dim intResults As Integer
Dim TestPassing As New clsTestPassing()
' Load some data
TestPassing.intAccessStatus = &H11223344
TestPassing.strUserName = "patrick"
intResults = TestPassing.ReadTestPassing()
Console.WriteLine("Access Status = " & Hex
(TestPassing.intAccessStatus))
Console.WriteLine("User Name <" &
TestPassing.strUserName & ">")
End Sub
End Module
<StructLayout(LayoutKind.Sequential)> Public Structure
DATA_TestPassing
Public AccessStatus As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=20)>
Public UserName() As Byte
End Structure
Public Class clsTestPassing
Dim DataEncode As New System.Text.ASCIIEncoding()
Dim m_strUserName As String
Dim REC_TestPassing As New DATA_TestPassing()
Private Const SIZE_TestPassing_UserName As Integer = 16
Private Const ASIS_TestPassing_UserName As Integer = 20
Public Sub New()
ReDim REC_TestPassing.UserName(20)
Console.WriteLine("New invoked")
End Sub
Public Property intAccessStatus() As Integer
Get
Return REC_TestPassing.AccessStatus
End Get
Set(ByVal Value As Integer)
REC_TestPassing.AccessStatus = Value
End Set
End Property
Public Property strUserName() As String
Get
Return m_strUserName
End Get
Set(ByVal Value As String)
If (Value.Length > SIZE_TestPassing_UserName)
Then
m_strUserName = Value.Substring(0,
SIZE_TestPassing_UserName)
Else
m_strUserName = Value
End If
End Set
End Property
Private Sub UnloadTestPassing()
Dim intPosition As Integer
m_strUserName = DataEncode.GetString
(REC_TestPassing.UserName)
intPosition = m_strUserName.IndexOf(Chr(0))
If intPosition = 0 Then
m_strUserName = ""
Else
m_strUserName = m_strUserName.Substring(0,
intPosition)
End If
End Sub
Private Sub LoadTestPassing()
Encoding.ASCII.GetBytes(m_strUserName.ToCharArray,
0, m_strUserName.Length, REC_TestPassing.UserName, 0)
REC_TestPassing.UserName(m_strUserName.Length) = 0
End Sub
Private Declare Function AccessTestPassing _
Lib "c:\Pat\VS6\VC6
\TestUDTPassing\debug\TestUDTPassing" _
(ByVal intAccessType As Integer, _
ByRef REC_TestPassing As DATA_TestPassing) _
As Integer
Public Function ReadTestPassing() As Integer
Dim intAccessType As Integer
Dim intResults As Integer
LoadTestPassing()
intAccessType = &HAABBCCDD
intResults = AccessTestPassing(intAccessType, _
REC_TestPassing)
UnloadTestPassing()
End Function
End Class
******************************************
* *
* TestUDTPassing DLL DEF source code *
* *
******************************************
LIBRARY TestUDTPassing
EXPORTS
******************************************
* *
* TestUDTPassing DLL CPP source code *
* *
******************************************
/*
TestUDTPassing.cpp
This module is the DLL that interfaces VB.NET/C++
to test passing a UDT with a string
Modification History
DATE PROGRAMMER Modification
---------- --------------------- ----------------------
-----------
2002/05/06 Patrick Ireland Original
2002/08/12 Patrick Ireland Update documentation
*/
/**********************************************************
**********
*
*
* System
includes *
*
*
***********************************************************
*********/
#include <windows.h>
#include <stdio.h>
/**********************************************************
**********
*
*
* Program
definitions *
*
*
***********************************************************
*********/
#define MODULE_NAME "TestUDTPassing"
#define MODULE_SPACE " "
#define MODULE_COPYRIGHT "(C) Copyright 2002 "
#define MODULE_OWNER "by Patrick Wayne Ireland "
#define MODULE_AUTHOR "Patrick Wayne Ireland "
#define MODULE_RIGHTS "All Rights Reserved "
#define MODULE_VERSION "2000/08/14 21:30 "
/**********************************************************
**********
*
*
* Structure
definitions *
*
*
***********************************************************
*********/
typedef struct
{
int intAccessStatus;
char szUserName [ 20 ];
} TestPassing;
/**********************************************************
**********
*
*
* Function
Prototypes *
*
*
***********************************************************
*********/
static void HexDump
(char * pszHeaderMessage,
BYTE * pabBytesToDump,
long lBytesToDump);
/**********************************************************
**********
*
*
* AccessTestPassing
() *
*
*
***********************************************************
*********/
DWORD __stdcall AccessTestPassing
(int intAccessType,
TestPassing * pTestPassing)
{
printf ("sizeof TestPassing %d\n",
sizeof (TestPassing));
HexDump ("AccessStatus",
(BYTE *) &intAccessType,
sizeof (int));
HexDump ("Record",
(BYTE *) pTestPassing,
sizeof (TestPassing));
strcpy ((char *) pTestPassing->szUserName,
"HELLO WORLD");
pTestPassing->intAccessStatus = 0x12345678;
HexDump ("Out Record",
(BYTE *) pTestPassing,
sizeof (TestPassing));
return 0;
Quote:
} // DWORD __stdcall AccessTestPassing
//
// extern "C" __declspec(dllexport) DWORD __stdcall
AccessTestPassing
/**********************************************************
**********
*
*
* Hexdump Support
Data *
*
*
***********************************************************
*********/
static char achPrintableChars [256] =
{ '.', '.', '.', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.', '.', '.',
' ', '!', '"', '#', '$', '%', '&', '\'',
'(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', ':', ';', '<', '=', '>', '?',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', '{', '|', '}', '~', '.',
'.', '.', '.', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.', '.', '.' };
static char achHexAsAscii [16] =
{ '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
/**********************************************************
**********
*
*
* HexDump
() *
*
*
***********************************************************
*********/
static void HexDump
(char * pszHeaderMessage,
BYTE * pabBytesToDump,
long lBytesToDump)
{
char szOutputLine [51];
long lOutputIndex;
long lByteCount;
long
...
read more »