Click here to Skip to main content
12,512,130 members (53,383 online)
Click here to Skip to main content

Stats

52.1K views
1.6K downloads
52 bookmarked
Posted

How to do CreateFileMapping in a C++ DLL and access it in C#, VB and C++

, 10 Mar 2009 CPOL
This is yet another example for memory mapped files. What is cool though is unlike other samples, I have a SetData(TCHAR* Key, TCHAR* value) / GetData(TCHAR* key) pattern here.
tubelite
bin
Client_CSharp.exe
Client_CSharp.vshost.exe
Client_CSharp.vshost.exe.manifest
Client_VBNET.exe
Client_Win32Console.exe
Client_Win32Console.ilk
SHAREDMEM.dll
SHAREDMEM.exp
SHAREDMEM.ilk
SHAREDMEM.lib
CSharpConsumer
bin
Debug
WindowsFormsApplication1.exe
Properties
SHAREDMEM
module.def
Release
mt.dep
sharedmem.dll.intermediate.manifest
sharedmem.pch
vc90.idb
sharedmem.vcproj.Pranav-PC.Pranav.user
UnmanagedConsumer
Release
mt.dep
Test1.exe.intermediate.manifest
vc90.idb
Test1.vcproj.Pranav-PC.Pranav.user
VBNETConsumer
bin
My Project
Application.myapp
// Test1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "windows.h"
#include "conio.h"

typedef TCHAR* (*PGETFUN)(TCHAR* key);
typedef void (*PSETFUN)(TCHAR* key, TCHAR* value);

int _tmain(int argc, _TCHAR* argv[])
{


	HMODULE hModule = LoadLibrary(L"SharedMem.dll");
	PSETFUN setfuncptr = (PSETFUN)GetProcAddress(hModule, "SetValue");
	PGETFUN getfuncptr = (PGETFUN)GetProcAddress(hModule, "GetValue");

	while(true){

		printf("\nPress S=Set G=Get E=Exit\n");

		switch(_getch())
		{

		case 'S':
			{
				printf("Enter Key Value Now :");
				TCHAR key[MAX_PATH], value[MAX_PATH];
				scanf("%S %S", key, value);
				setfuncptr(key, value);
			}
			break;

		case 'G':
			{
				printf("Enter Lookup Key: ");
				TCHAR key[MAX_PATH];
				scanf("%S",key);
				printf("Found Value %S", getfuncptr(key));
			
			}
			break;

		case 'E':
			goto end;
			break;

		}
	}

end:
	return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

nkrscorpio
Software Developer
United States United States
No Biography provided

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160929.1 | Last Updated 10 Mar 2009
Article Copyright 2008 by nkrscorpio
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid