473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How to make a direct entry into a DLL that requires a point to an unsigned FAR?

Although the particular DLL is for the National Instruments
flexmotion32.dll I've convinced myself that it has something to do
with the 'u16 FAR' data type. This is the particular Dll function that
is giving me a headache:

FLEXFUNC flex_read_port_rtn (BOARD, u8 port, u16 FAR *portData);

Is there anything special I have to do to call this function since the
DLL wants a pointer to an u16 FAR?

What exactly does FAR mean and what are the implications when calling
from C#? Can I ignore FAR and just use a reference to an ushort
(Uint16)? I have had success calling flex_set_port and changing the
state of output bits. I've also successfully used the DllImport to
communicate with the PCI-GPIB board using the National Instruments
gpib-32.dll.

Here's what I've tried so far, but the portData always comes back as
‘69' regardless of the bit is ON or OFF.

Method 1:
// Read I/O Port
[DllImport("c:/WINNT/system32/FlexMotion32.dll",
EntryPoint="flex_read_port_rtn")]
static extern int flex_read_port_rtn(byte boardID, byte port,
[MarshalAs(UnmanagedType.LPArray)] uint[] portData);

…In the CdigitalIO object I have the following method:

public int readBitState(digInputNames index)
{
ushort[] portData = new ushort[1];
portData[0] = 0;
byte boardID = 1; //Motion card ID

//Make call to the Flexmotion32.dll function
status = flex_read_port_rtn(inputBit.boardID, inputBit.port,
portData);
}

I now run the program with all the bits on port 1 off except for bit
0. When I run the program the port data comes back as ‘69' regardless
of whether the input is ON or OFF.

Method 2:
// Read I/O Port
[DllImport("c:/WINNT/system32/FlexMotion32.dll",
EntryPoint="flex_read_port_rtn")]
static extern int flex_read_port_rtn(byte boardID, byte port,
ref ushort portData);

Same problem, I get portData as ‘69'.

Any suggestions would be greatly appreciation.
Nov 15 '05 #1
1 2551
>What exactly does FAR mean and what are the implications when calling
from C#? Can I ignore FAR and just use a reference to an ushort
(Uint16)?
Yes, you should be able to ignore FAR, it has no meaning in the 32-bit
flat address space.

Method 1:
// Read I/O Port
[DllImport("c:/WINNT/system32/FlexMotion32.dll",
EntryPoint="flex_read_port_rtn")]
static extern int flex_read_port_rtn(byte boardID, byte port,
[MarshalAs(UnmanagedType.LPArray)] uint[] portData);
I assume you really have the last parameter as ushort[], at least
that's what you're passing in at the call site.

Method 2:
// Read I/O Port
[DllImport("c:/WINNT/system32/FlexMotion32.dll",
EntryPoint="flex_read_port_rtn")]
static extern int flex_read_port_rtn(byte boardID, byte port,
ref ushort portData);
This one should perform somewhat better if you're only going to pass
in a single ushort to the portData parameter.

Same problem, I get portData as ‘69'.


I don't know why you get back unexpected results, the code looks
correct as far as I can tell.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #2

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

Similar topics

5
by: Nadav | last post by:
Hi, I am trying to get a direct pointer to the address of the screen ( something like 0x0b00 in the happy DOS days ), how can I do that? Should this be done in the kernel or it can also be done...
19
by: Swaregirl | last post by:
Hello, I would like to build a website using ASP.NET. I would like website visitors to be able to download code that I would like to make available to them and that would be residing on my...
6
by: david | last post by:
When I compile a window form client for web service, there is error message as follows: Program 'D:\usr\winVBcontrol\WinClient4WebServiceFileCS\obj\Debug\WinClient4WebServiceFileCS.exe' does not...
6
by: Prashant Bhuptani | last post by:
Hi Guys, I am trying to use a C++ dll in VB.NET code. I have imported the dll in the following manner: <code> Imports System.Runtime.InteropServices
16
by: digitalorganics | last post by:
What's the difference between initializing class variables within the class definition directly versus initializing them within the class's __init__ method? Is there a reason, perhaps in certain...
21
by: Chen Shusheng | last post by:
Hello, I have a small piece of code that I want to directly assign a segment of memory to a pointer. But complier tell me wrong. Pls you help.Codes below: ------------------ int * p;...
6
by: pete142 | last post by:
When I compile this code: typedef unsigned char BYTE; BYTE * IpString(unsigned int ip) { static BYTE ipString; ipString = (BYTE) 0xff & (ip >24); ipString = (BYTE) 0xff & (ip >16);
1
by: stevenjs | last post by:
Greeings, all, Flash 8 has quiz templates which are coded for multiple choice, true/false, text statement, and matching types of questions, along with hotspots and probably anoher type I am...
88
by: santosh | last post by:
Hello all, In K&R2 one exercise asks the reader to compute and print the limits for the basic integer types. This is trivial for unsigned types. But is it possible for signed types without...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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
tracyyun
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...
0
isladogs
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...

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.