473,479 Members | 2,060 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Pointer in API making life hell

Hello there.
There is a DLL file which contains a function as below. It will return me
the device name i.e pcDevName

ULONG MTMICRGetDevice (
DWORD dwDeviceContext,
char *pcDevName
);

Example given to use the above function is as below
-----------------------------------------
#define DEVICE_NAME_LEN 128
int i=1;
DWORD dwResult;
char pcDevName[DEVICE_NAME_LEN] = "";
while ((dwResult =
MTMICRGetDevice(i,(char*)pcDevName))!=MICR_ST_DEVI CE_NOT_FOUND
{
//Device found, increment the device number
i++;
}

My defination in VB .NET to get the pcDevName
--------------------------------------
Declare Auto Function fGetDeviceName Lib "mtmcrapi.dll" Alias
"MTMICRGetDevice" (ByVal intNum As Integer, ByRef strDName As Char) As
Integer

Private Sub cmdConnect_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdConnect.Click

Dim strMy As Char

Dim intI As Integer

Dim strRst As Integer

intI = 2

strRst = Win32.fGetDeviceName(intI, strMy)

MessageBox.Show(strMy.ToString, strRst.ToString)

End Sub

The function is returning the value 0 (that means ok) but the device name is
one char junk.
-WHAT IS WRONG???
-Is there a way to get the data by using the memory address in VB .NET

Nov 21 '05 #1
3 2472
Hi,

"AAVarda" <as***@data-aware.com> wrote in message
news:OI**************@tk2msftngp13.phx.gbl...
Hello there.
There is a DLL file which contains a function as below. It will return me
the device name i.e pcDevName

ULONG MTMICRGetDevice (
DWORD dwDeviceContext,
char *pcDevName
);

Example given to use the above function is as below
-----------------------------------------
#define DEVICE_NAME_LEN 128
int i=1;
DWORD dwResult;
char pcDevName[DEVICE_NAME_LEN] = "";
while ((dwResult =
MTMICRGetDevice(i,(char*)pcDevName))!=MICR_ST_DEVI CE_NOT_FOUND
{
//Device found, increment the device number
i++;
}

My defination in VB .NET to get the pcDevName
--------------------------------------
Declare Auto Function fGetDeviceName Lib "mtmcrapi.dll" Alias
"MTMICRGetDevice" (ByVal intNum As Integer, ByRef strDName As Char) As
Integer

Private Sub cmdConnect_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdConnect.Click

Dim strMy As Char

Dim intI As Integer

Dim strRst As Integer

intI = 2

strRst = Win32.fGetDeviceName(intI, strMy)

MessageBox.Show(strMy.ToString, strRst.ToString)

End Sub

The function is returning the value 0 (that means ok) but the device name
is one char junk.
-WHAT IS WRONG???
-Is there a way to get the data by using the memory address in VB .NET


Try:
Imports System.Text

Declare Ansi Function fGetDeviceName Lib "mtmcrapi.dll" Alias
"MTMICRGetDevice" (ByVal Context As Integer, _
ByVal NameSB As StringBuilder) As Integer

Dim ret As Integer
Dim context As Integer
Dim nameSB As New StringBuilder(128)

context = 2
ret = Win32.fGetDeviceName( context, nameSB )

MessageBox.Show( nameSB.ToString(), ret.ToString() )

hth,
Greetings
Nov 21 '05 #2
THANK YOU :) you guys are really really gr8. Problem solved
"Bart Mermuys" <bm*************@hotmail.com> wrote in message
news:uc**************@TK2MSFTNGP09.phx.gbl...
Hi,

"AAVarda" <as***@data-aware.com> wrote in message
news:OI**************@tk2msftngp13.phx.gbl...
Hello there.
There is a DLL file which contains a function as below. It will return me
the device name i.e pcDevName

ULONG MTMICRGetDevice (
DWORD dwDeviceContext,
char *pcDevName
);

Example given to use the above function is as below
-----------------------------------------
#define DEVICE_NAME_LEN 128
int i=1;
DWORD dwResult;
char pcDevName[DEVICE_NAME_LEN] = "";
while ((dwResult =
MTMICRGetDevice(i,(char*)pcDevName))!=MICR_ST_DEVI CE_NOT_FOUND
{
//Device found, increment the device number
i++;
}

My defination in VB .NET to get the pcDevName
--------------------------------------
Declare Auto Function fGetDeviceName Lib "mtmcrapi.dll" Alias
"MTMICRGetDevice" (ByVal intNum As Integer, ByRef strDName As Char) As
Integer

Private Sub cmdConnect_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdConnect.Click

Dim strMy As Char

Dim intI As Integer

Dim strRst As Integer

intI = 2

strRst = Win32.fGetDeviceName(intI, strMy)

MessageBox.Show(strMy.ToString, strRst.ToString)

End Sub

The function is returning the value 0 (that means ok) but the device name
is one char junk.
-WHAT IS WRONG???
-Is there a way to get the data by using the memory address in VB .NET


Try:
Imports System.Text

Declare Ansi Function fGetDeviceName Lib "mtmcrapi.dll" Alias
"MTMICRGetDevice" (ByVal Context As Integer, _
ByVal NameSB As StringBuilder) As Integer

Dim ret As Integer
Dim context As Integer
Dim nameSB As New StringBuilder(128)

context = 2
ret = Win32.fGetDeviceName( context, nameSB )

MessageBox.Show( nameSB.ToString(), ret.ToString() )

hth,
Greetings

Nov 21 '05 #3
Hello,
-WHAT IS WRONG???
Whong is that a char* in C is not exactly a *pointer to char*. It's a
*pointer to a null-terminated string*.
Thus, it should be declared as String in VB (or StringBuilder if it's
going to be changed) if you don't want to get a "one char junk".

You should try this:

~
Declare Function fGetDeviceName Lib "mtmcrapi.dll" Alias
"MTMICRGetDevice" ( _
ByVal dwDeviceContext As Integer, _
<MarshalAs(UnmanagedType.LPStr)> ByVal pcDevName As StringBuilder _
) As Integer
~
-Is there a way to get the data by using the memory address in VB .NET
Look at Shared Marshal.PtrTo* methods.



Hope this helps,
Roman
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
2851
by: tuko | last post by:
Hello kind people. Can someone explain please the following code? /* Create Storage Space For The Texture */ AUX_RGBImageRec *TextureImage; /* Line 1*/ /* Set The Pointer To NULL...
23
3143
by: Ken Turkowski | last post by:
The construct (void*)(((long)ptr + 3) & ~3) worked well until now to enforce alignment of the pointer to long boundaries. However, now VC++ warns about it, undoubtedly to help things work on 64...
3
10270
by: sklett | last post by:
This BUG that is so ridiculous I can't believe they shipped 05 is making my life hell. I have tried the various solutions found on the web and none of them have worked thus far. What's even more...
6
2649
by: Simple Simon | last post by:
[posted separately to comp.unix.programmer and Can't figure out why this code generates a SIGSEGV in fillGlobalBuffer() (below). globalBuffer is allocated in caller.c, then its address is...
6
2290
by: zl2k | last post by:
hi, When I considered about preventing memory leaking, the method came up to my mind is using boost smart pointer if possible (use stl::vector instead of type, use smart pointer whenever declare...
51
4389
by: Kuku | last post by:
What is the difference between a reference and a pointer?
12
3851
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
26
3015
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I...
50
4421
by: Juha Nieminen | last post by:
I asked a long time ago in this group how to make a smart pointer which works with incomplete types. I got this answer (only relevant parts included): ...
0
7033
marktang
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,...
0
6903
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...
0
7027
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7071
jinu1996
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...
1
6726
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5318
agi2029
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,...
0
2987
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1291
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 ...
0
170
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.