Click here to Skip to main content
15,905,004 members
Home / Discussions / C#
   

C#

 
GeneralRe: Outlook "like" Date Groupings Pin
Gary Thom8-Jul-04 4:34
Gary Thom8-Jul-04 4:34 
Generalunderline Text in a Button Control Pin
isedf7-Jul-04 12:55
isedf7-Jul-04 12:55 
GeneralRe: underline Text in a Button Control Pin
Heath Stewart7-Jul-04 13:12
protectorHeath Stewart7-Jul-04 13:12 
Questionhow difficult does getting an instance by handle have to be? Pin
spazzman7-Jul-04 11:36
spazzman7-Jul-04 11:36 
AnswerRe: how difficult does getting an instance by handle have to be? Pin
Heath Stewart7-Jul-04 12:33
protectorHeath Stewart7-Jul-04 12:33 
AnswerRe: how difficult does getting an instance by handle have to be? Pin
MilesAhead11-Jul-04 16:44
MilesAhead11-Jul-04 16:44 
GeneralRe: how difficult does getting an instance by handle have to be? Pin
spazzman12-Jul-04 5:50
spazzman12-Jul-04 5:50 
GeneralRe: how difficult does getting an instance by handle have to be? Pin
MilesAhead12-Jul-04 6:55
MilesAhead12-Jul-04 6:55 
Okay, I think a more straight-forward solution to
what you want to do, provided both applications
are on the same machine, is to use shared memory
via Memory Mapped Files. C# is a bit of a pain
in that it only gives the PInvoke mechanism for
doing Win32 stuff, but using a page of swap file
in a memory mapped file for shared memory isn't
that difficult. There are a couple articles
showing how to get at memory mapped files from
C# on Code Project. Also you can use the tool
at http://pinvoke.net to pull the prototypes
adjusted for C# right into the editor for you.

The main advantage of using a named memory mapped
file with app instances is that you don't need to
worry about handles. Using a GUID string in the
memory mapped filename makes sure it's unique.
So in your application you try to create the
Memory Mapped File with CreateFileMapping(). If you get a handle but Marshal.GetLastWin32Error() returns ERROR_ALREADY_EXISTS then you're in the secondary instance. Otherwise if the creation
succeeded you're in the primary.

The secondary instance copies info it wants to
send to the primary in the shared memory. The
primary instance reads it out. To avoid mangling
the data you can use a mutex to control access.
Before it quits, the secondary instance gets the
mutex, copies the info to the shared memory,
releases the mutex, then exits(if that's what
you want it to do.) The primary gets the mutex,
checks for new data in the shared memory, if it
finds it then it copies the data out, then releases the mutex.

It sounds a bit more complicated than it is.
I would look for examples of Memory Mapped
Files. Using one page of system swap file
is the simplest case with fewest system
quirks to worry about.

As I suggested, the TellTail component on
www.torry.net does what you're trying to
do. Delphi is pretty Enlish-like so even
if you don't program in it often you can
read the source and get the gist. Besides,
Win32 calls are going to be pretty much the
same no matter what language you call them
with.

GeneralTreeView with ComboBoxes in TreeNodes Pin
theoutlander7-Jul-04 11:19
theoutlander7-Jul-04 11:19 
GeneralRe: TreeView with ComboBoxes in TreeNodes Pin
Heath Stewart7-Jul-04 12:38
protectorHeath Stewart7-Jul-04 12:38 
GeneralHowTo change color on statusbar Pin
QzRz7-Jul-04 9:54
QzRz7-Jul-04 9:54 
GeneralRe: HowTo change color on statusbar Pin
Heath Stewart7-Jul-04 12:50
protectorHeath Stewart7-Jul-04 12:50 
Generalproblem with SQLServer CE Pin
JulienR7-Jul-04 8:51
JulienR7-Jul-04 8:51 
GeneralRe: problem with SQLServer CE Pin
Heath Stewart7-Jul-04 12:56
protectorHeath Stewart7-Jul-04 12:56 
GeneralRe: problem with SQLServer CE Pin
Anonymous8-Jul-04 2:30
Anonymous8-Jul-04 2:30 
GeneralRe: problem with SQLServer CE Pin
Heath Stewart8-Jul-04 3:12
protectorHeath Stewart8-Jul-04 3:12 
GeneralCustom Listbox controls Pin
kam33mitch7-Jul-04 8:08
kam33mitch7-Jul-04 8:08 
GeneralRe: Custom Listbox controls Pin
Heath Stewart7-Jul-04 13:04
protectorHeath Stewart7-Jul-04 13:04 
GeneralRe: Custom Listbox controls Pin
kam33mitch7-Jul-04 14:40
kam33mitch7-Jul-04 14:40 
Questionbitmap to byte array ? Pin
kendao7-Jul-04 7:10
kendao7-Jul-04 7:10 
AnswerRe: bitmap to byte array ? Pin
Grimolfr7-Jul-04 8:05
Grimolfr7-Jul-04 8:05 
AnswerRe: bitmap to byte array ? Pin
Heath Stewart7-Jul-04 8:50
protectorHeath Stewart7-Jul-04 8:50 
GeneralProgress Bar in Status bar panel Pin
bouli7-Jul-04 4:38
bouli7-Jul-04 4:38 
GeneralRe: Progress Bar in Status bar panel Pin
Heath Stewart7-Jul-04 5:55
protectorHeath Stewart7-Jul-04 5:55 
GeneralRe: Progress Bar in Status bar panel Pin
bouli7-Jul-04 23:52
bouli7-Jul-04 23:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.