473,785 Members | 3,032 Online
Bytes | Software Development & Data Engineering Community
+ 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 1791
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.co m

"Sune" <su**********@h otmail.comwrote in message
news:11******** *************@2 2g2000hsm.googl egroups.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.guar d.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.c om

"Sune" <sune_ahlg...@h otmail.comwrote in message

news:11******** *************@2 2g2000hsm.googl egroups.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_RE AD = 0x0020;
const int PAGE_EXECUTE_RE ADWRITE = 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_AC CESS = 0x001F;

[StructLayout( LayoutKind.Sequ ential )]
class SECURITY_ATTRIB UTES
{
//int nLength;
//int lpSecurityDescr iptor;
//int bInheritHandle;
}

[DllImport("kern el32.dll")]
static extern int CreateFileMappi ngA ( uint hFile,
SECURITY_ATTRIB UTES
lpFileMappigAtt ributes,
int flProtect,
int dwMaximumSizeHi gh,
int dwMaximumSizeLo w,
string lpName);

[DllImport("kern el32.dll")]
static extern IntPtr MapViewOfFile ( int hFileMappingObj ect,
int dwDesiredAccess ,
int dwFileOffsetHig h,
int dwFileOffsetLow ,
int dwNumberOfBytes ToMap);

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

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

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

Sep 10 '07 #4

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

Similar topics

30
3142
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 wish that my predecessor had followed) but -- alas -- being a relative beginner to Access, I can't see the reasoning behind one of the points and the site does not provide any rationale / explanation for its presence either: 2. Thou shalt never...
22
2044
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 explained that what I needed was possible but he was unsure if he had the capabillities to carry it out. He has started drawing some plans and I will attempt to explain what I will require from the software. It will need to be user friendly and...
2
1609
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 subfrm1 will have id=1 and lookup=1 subfrm2 will have id=1 and lookup=12
14
2587
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 200 W. Monroe St. Suite 900 Chicago, IL 60606 (312) 222-9400 Location: www.imginc.com/IMG/About+IMG/chicago.htm
5
3505
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 server backend. If I create a view containing value from table MAIN and enter data into it from a form in access everything is ok. However if I make a vew with both tables MAIN and table LOOKUP I get the error above. Table MAIN contains some...
8
3322
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 Server. What would be the best way to convert the VBA code I use in Access to SQL Server - being only marginally familiar with T-SQL syntax and not at all familiar with what can or cannot be done? --
9
2577
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
3557
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: class X( object ): y = 'private value' def get_y( self ): return self.y
1
6791
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 you to look up the next smallest value to what you provided, and return any corresponding field from the table. Very useful for looking up things like currency exchange rates, tax rates, etc., where there might not be an entry for every day/income...
4
4387
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 stock database. For now, it will simply track what products come in (Stocks bought by Project) and what products go out (Stocks sold to by Project) . There are three tables: Products, Transactions and Projects.
0
10327
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
10151
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...
1
7499
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...
0
6740
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
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
2
3647
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
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.