Click here to Skip to main content
13,150,178 members (60,998 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi ,

I have an unmanaged DLL (c++)...How can i make use of it in my c# windows application....

Thanks in advance
Posted 15-Nov-12 0:41am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You need to use Platform Invoke:[^]

It's easier than it sounds (depending on the parameters you need to hand over) - at a minimum, it's just a case of adding an attribute to a method declaration:
private static extern int SetForegroundWindow(IntPtr hwnd);
Uses the method SetForegroundWindow from the system DLL file "User32.dll"
You can then just call it in C#:

public static void SingleInstance(this Process thisProcess)
    foreach (Process proc in Process.GetProcessesByName(thisProcess.ProcessName))
        if (proc.Id != thisProcess.Id)
            ShowWindow(proc.MainWindowHandle, SW_RESTORE);

[edit]Typo: SetForgrondWindow for SetForegroundWindow - OriginalGriff[/edit]
darshan559 23-Nov-12 10:26am
@OriginalGriff :thanku for ur answer...i got d idea and i tried with simple example and it worked great :) but the problem now is i ve to pass a structure type argument from c# application to unmanaged DLL... how can i achieve this ??
OriginalGriff 23-Nov-12 11:32am
Time to start reading! (I can't give specific advice on a general subject - the MSDN link covers it pretty well)

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170924.2 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100