473,480 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Access lookup-service managed by C module

Hi all,

I'm not a C# programmer so please be gentle:

Prereq:
---------------
- The lookup service (see below) implemented by a C module cannot be
re-written in C# ;-)
- The lookup service is to be loaded into the process of the C#
application, i.e. I want to avoid expensive IPC

1)
I got a C module that organizes a big block of memory into a fairly
nice lookup service. This C module exposes a C API.
>From my understanding, C# being a pointerless language, C# client
code cannot by any means, by mistake, access the memory block managed
by the C module. Is this correct? Will the bridge between C and C#
open the can of worms I try to avoid by using a pointerless language?

Note:
In C/C++, a rouge pointer can very easily damage the lookup service
and this would not be noticed until several days have passed. This is
not acceptable.

Thank you for your time
/Sune

Sep 9 '07 #1
3 1780
Sune,

Well, you could access the memory block that is used by the C module if
you REALLY wanted to, but generally, the way it works is that you are going
to call the API through the P/Invoke layer, which is going to be responsible
for marshaling the .NET types to the unmanaged module and back.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Sune" <su**********@hotmail.comwrote in message
news:11*********************@22g2000hsm.googlegrou ps.com...
Hi all,

I'm not a C# programmer so please be gentle:

Prereq:
---------------
- The lookup service (see below) implemented by a C module cannot be
re-written in C# ;-)
- The lookup service is to be loaded into the process of the C#
application, i.e. I want to avoid expensive IPC

1)
I got a C module that organizes a big block of memory into a fairly
nice lookup service. This C module exposes a C API.
>>From my understanding, C# being a pointerless language, C# client
code cannot by any means, by mistake, access the memory block managed
by the C module. Is this correct? Will the bridge between C and C#
open the can of worms I try to avoid by using a pointerless language?

Note:
In C/C++, a rouge pointer can very easily damage the lookup service
and this would not be noticed until several days have passed. This is
not acceptable.

Thank you for your time
/Sune
Sep 9 '07 #2
On 10 Sep, 01:00, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Sune,

Well, you could access the memory block that is used by the C module if
you REALLY wanted to, but generally, the way it works is that you are going
to call the API through the P/Invoke layer, which is going to be responsible
for marshaling the .NET types to the unmanaged module and back.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"Sune" <sune_ahlg...@hotmail.comwrote in message

news:11*********************@22g2000hsm.googlegrou ps.com...
Hi all,
I'm not a C# programmer so please be gentle:
Prereq:
---------------
- The lookup service (see below) implemented by a C module cannot be
re-written in C# ;-)
- The lookup service is to be loaded into the process of the C#
application, i.e. I want to avoid expensive IPC
1)
I got a C module that organizes a big block of memory into a fairly
nice lookup service. This C module exposes a C API.
>From my understanding, C# being a pointerless language, C# client
code cannot by any means, by mistake, access the memory block managed
by the C module. Is this correct? Will the bridge between C and C#
open the can of worms I try to avoid by using a pointerless language?
Note:
In C/C++, a rouge pointer can very easily damage the lookup service
and this would not be noticed until several days have passed. This is
not acceptable.
Thank you for your time
/Sune
Thanks Nicholas!

Sep 10 '07 #3
Sune wrote:
Prereq:
---------------
- The lookup service (see below) implemented by a C module cannot be
re-written in C# ;-)
- The lookup service is to be loaded into the process of the C#
application, i.e. I want to avoid expensive IPC
You asked the same question in the Java group. Do you need the
solution in C# or Java or both ?
1)
I got a C module that organizes a big block of memory into a fairly
nice lookup service. This C module exposes a C API.
>>From my understanding, C# being a pointerless language, C# client
code cannot by any means, by mistake, access the memory block managed
by the C module. Is this correct? Will the bridge between C and C#
open the can of worms I try to avoid by using a pointerless language?
Pure managed C# can not overwrite memory.

You will need to call unmanaged (native) code to do what
you want.

And that code can overwrite memory.

If you want to have your C# code access global memory
managed by the C code, then I think you can use only your C# code and
native code provided by Microsoft.

See below for a code snippet (some C# code that communicates
via some Delphi code via global memory.

Arne

==============================

using System;
using System.Runtime.InteropServices;

class MainClass
{
const int PAGE_READONLY = 0x0002;
const int PAGE_READWRITE = 0x0004;
const int PAGE_EXECUTE = 0x0010;
const int PAGE_EXECUTE_READ = 0x0020;
const int PAGE_EXECUTE_READWRITE = 0x0040;
const int PAGE_GUARD = 0x0100;
const int PAGE_NOACCESS = 0x0001;
const int PAGE_NOCACHE = 0x0200;
const int FILE_MAP_COPY = 0x0001;
const int FILE_MAP_WRITE = 0x0002;
const int FILE_MAP_READ = 0x0004;
const int FILE_MAP_ALL_ACCESS = 0x001F;

[StructLayout( LayoutKind.Sequential )]
class SECURITY_ATTRIBUTES
{
//int nLength;
//int lpSecurityDescriptor;
//int bInheritHandle;
}

[DllImport("kernel32.dll")]
static extern int CreateFileMappingA ( uint hFile,
SECURITY_ATTRIBUTES
lpFileMappigAttributes,
int flProtect,
int dwMaximumSizeHigh,
int dwMaximumSizeLow,
string lpName);

[DllImport("kernel32.dll")]
static extern IntPtr MapViewOfFile ( int hFileMappingObject,
int dwDesiredAccess,
int dwFileOffsetHigh,
int dwFileOffsetLow,
int dwNumberOfBytesToMap);

[DllImport("kernel32.dll")]
static extern int UnmapViewOfFile (IntPtr lpBaseAddress);

[DllImport("kernel32.dll")]
static extern int CloseHandle ( int hObject);

public static void Main(string[] args)
{
int mem = CreateFileMappingA(0xFFFFFFFF, null, PAGE_READWRITE,
0, 8192, "GBLMEM");
IntPtr data = MapViewOfFile(mem, FILE_MAP_WRITE, 0, 0, 8192);
Console.WriteLine("Run Delphi program and press enter");
Console.ReadLine();
int[] data2 = new int[2048];
Marshal.Copy( data, data2, 0, 3 );
UnmapViewOfFile(data);
CloseHandle(mem);
Console.WriteLine(data2[0]);
Console.WriteLine(data2[1]);
Console.WriteLine(data2[2]);
}
}

Sep 10 '07 #4

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

Similar topics

30
3087
by: Andante.in.Blue | last post by:
I just browsed through some of my Access links when I came across the Ten Commandments of Access (http://www.mvps.org/access/tencommandments.htm). Some of the points I heartily agree with (and...
22
2007
by: script-learner | last post by:
I currently own a fruit and veg business and wish to compuiterise my manual methods in order to reduce labour costs. I spoke to my son who is a whiz on computers and he had a good chat with me and...
2
1585
by: sparks | last post by:
I have a table with data like this id data data data lookup 1 ### ### ### 1 1 ### ### ### 12 I need to put this in 2 subforms...
14
2550
by: Kevin G. Anderson | last post by:
What: CAUG Meeting - QuickBooks IIF Files; Total Access Analyzer; CAUG Social When: Thursday, May 25, 2006, 6PM Who: Chris Monaghan and Kevin Anderson Where: The Information Management Group...
5
3495
by: ken | last post by:
Hi, I get the following error "Invalid input parameter values. Check the status values for detail". I have a SQL 2005 backend, and an access front end. I have two tables, MAIN, LOOKUP in my SQL...
8
3290
by: Darryl Kerkeslager | last post by:
Currently I am using the RegExp object to parse a large dataset in an Access table - but this table was exported from SQL Server, and the very correct question was asked - why not just do it in SQL...
9
2533
by: Michael M. | last post by:
Hi all, I would like to know how to access the NT/2000/XP/2003 Name cache; what I mean by this is: Open a Command Prompt and.., C:\> C:\>IPCONFIG /DISPLAYDNS
6
3535
by: Adam Donahue | last post by:
As an exercise I'm attempting to write a metaclass that causes an exception to be thrown whenever a user tries to access 'attributes' (in the traditional sense) via a direct reference. Consider:...
1
6770
by: scubasteve | last post by:
Looking up values from an Access table is simple. Simulating the 'Range Lookup' functionality from Excel's VLookup formula is a bit trickier. For those that aren't familiar with this, it allows...
4
4365
by: netnewbie78 | last post by:
Hello All, I don't have a problem (but maybe I will after I explain). I have a question with regards to something I saw in Access 2007. But first, a little backstory: I'm writing a very small...
0
6904
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
7080
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...
0
6895
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...
1
4770
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...
0
4476
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1296
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 ...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
176
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.