473,626 Members | 3,316 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DllImport: pointer to an array of far pointers to null-terminated character

Hello NG,

I have a mirror.dll written in C I would like to access from a C# console
application. However, I dont't know how to to it.

The dll is fairly well documented and I have access to the header files.
According to the documentation and the header files the function I need is
declared as follows:

extern "C" {
unsigned short far pascal InitMirror( int argc, char far * far *argv);
}

argc: # command line arguments the program was invoked with.
argv: pointer to an array of far pointers to null-terminated character
strings that contain the arguments the program was invoked with.
Returns zero if successfull, or a non-zero value if unable to initialize.

Now, I'm doing someting wrong, so my code always returns a non-zero value.

using System;
using System.Runtime. InteropServices ;
namespace MirrorDemo
{
class Demo {
[DllImport("mirr or.dll", EntryPoint="Ini tMirror",
SetLastError=fa lse, CharSet=CharSet .Ansi, ExactSpelling=t rue,
CallingConventi on=CallingConve ntion.StdCall)]
public static extern int InitMirror(int argc, String [] argv);

[STAThread]
static void Main(string[] args) {
int error;
error = InitMirror(args .Length, args);
if (error != 0) {
Console.WriteLi ne("Error: {0}", error);
}
}
}
}

This doesn't work as I already expected. However I dont't know how to do it.
How should the code look like?

Any hints are welcome!

Thanks in advance.

Peter Gloor
Nov 15 '05 #1
1 2985
Well, independently of any other problems you might be having, your C++
routine returns a 16 bit unsigned value, but your p/invoke declaration is
for a 32 bit signed value. So you are likely getting garbage in the upper 16
bits on the managed side, which could account for your troubles.

Also, you might want to double-check the default marshalling for arrays of
strings to make sure that string[] marshals to char** and not to a
safearray, or an array of bstr's, etc. (I think the default behavior is
probably to marshal as an in param of char** as you are assuming, just
wanted to point that out.)

"Peter Gloor" <p_*****@hotmai l.com> wrote in message
news:eo******** ******@TK2MSFTN GP11.phx.gbl...
Hello NG,

I have a mirror.dll written in C I would like to access from a C# console
application. However, I dont't know how to to it.

The dll is fairly well documented and I have access to the header files.
According to the documentation and the header files the function I need is
declared as follows:

extern "C" {
unsigned short far pascal InitMirror( int argc, char far * far *argv); }

argc: # command line arguments the program was invoked with.
argv: pointer to an array of far pointers to null-terminated character
strings that contain the arguments the program was invoked with.
Returns zero if successfull, or a non-zero value if unable to initialize.

Now, I'm doing someting wrong, so my code always returns a non-zero value.

using System;
using System.Runtime. InteropServices ;
namespace MirrorDemo
{
class Demo {
[DllImport("mirr or.dll", EntryPoint="Ini tMirror",
SetLastError=fa lse, CharSet=CharSet .Ansi, ExactSpelling=t rue,
CallingConventi on=CallingConve ntion.StdCall)]
public static extern int InitMirror(int argc, String [] argv);

[STAThread]
static void Main(string[] args) {
int error;
error = InitMirror(args .Length, args);
if (error != 0) {
Console.WriteLi ne("Error: {0}", error);
}
}
}
}

This doesn't work as I already expected. However I dont't know how to do it. How should the code look like?

Any hints are welcome!

Thanks in advance.

Peter Gloor

Nov 15 '05 #2

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

Similar topics

4
16455
by: Bryan Parkoff | last post by:
I want to allocate pointer array into memory so pointer array contains ten pointers. It would be 4 bytes per pointer to be total 40 bytes. Looks like below for example. unsigned char* A = new unsigned char ; It has only one pointer contains 1,000 bytes. How can I do this to create pointer list like below. unsigned char** B = new (unsigned char*) ; // Pointer List contains
22
4795
by: Christopher Benson-Manica | last post by:
Is adding 0 to a pointer to non-void that is equal to NULL legal? int *p=NULL; p+=0; -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
5
1575
by: Brett | last post by:
Sorry for the rookie question.... If I have a pointer array (for example): char *colors = { "blue", "green" }; and I want to add yellow to this array later in my code....how would I do
1
943
by: Nick Samia | last post by:
My problem is I am trying to migrate code from Version 6.0 C++ to C++ .NET managed code and cannot figure out the __gc syntax for a pointer to an array of pointers. In C++ I can declare an object pointer type to an array of object pointers like this. In my .h file I declare CAssemFloat **floatPtr; In the cpp file I would create the array by
1
2160
by: MyCGal | last post by:
Hi, I have this code I wrote to copy any length lines into array of pointers. The problem is after storing the individual lines into the char pointer array, the dispaly() chops off some lines while retains the others (mostly last and first line in the array). I guess there is some allocation problem but don't know where exactly. Please suggest. int readlines(char *lineptr, int maxlines) { int len, nlines,i; char *p,...
2
15399
by: saravanakumar | last post by:
Hi, Can any one explain me the difference between Array of pointers and pointer array? Regards Saravanan
5
3636
by: Immortal Nephi | last post by:
I would like to design an object using class. How can this class contain 10 member functions. Put 10 member functions into member function pointer array. One member function uses switch to call 10 member functions. Can switch be replaced to member function pointer array? Please provide me an example of source code to show smart pointer inside class. Thanks....
13
1869
by: pereges | last post by:
Hi, can some one please tell me why this program is not able to function properly. I have a array a and i am trying to create a pointer array b which points to elements less than 40 in a. #include <stdio.h> #include <math.h> #include <stdlib.h> void create_ptr_list(int *a, int ***b, int n, int *size_ptr) {
3
13809
by: JoxC | last post by:
Hey guys, I was wondering if there is an *efficient* way in setting every pointer in an array of pointers to NULL? memset cannot work for compatibility reasons, but I was playing a bit with memcpy: I built an array of NULL-pointers and tried to memcopy it to the array I wish to clear, but I couldn't find a working solution. e.g.: int** NULL_ARRAY; NULL_ARRAY = (int **) malloc (x * sizeof(int*)); int** array; array = (int **) malloc (x *...
1
2066
by: alansharp | last post by:
Hi guys Im attempting to write conways Game of life and need to use a pointer and 2 arrays. The reason im using a pointer is hopefully to speed up the code rather than copying the array > processing it and copying it back. I found this code in an old post on the forum but having never used pointers before im a little lost with what to do. int array = new int; fixed(int* pointer = &array) { //use the pointer
0
8272
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, 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...
0
8205
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,...
0
8713
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8644
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 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...
0
8514
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 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...
1
6126
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 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...
1
2632
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
1
1817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1516
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 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...

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.