Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#ASP.NET
Hi ,
 
I have an unmanaged DLL (c++)...How can i make use of it in my c# windows application....
 
Thanks in advance
Darshan
Posted 15-Nov-12 0:41am

1 solution

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

Solution 1

You need to use Platform Invoke: http://msdn.microsoft.com/en-us/library/26thfadc.aspx[^]
 
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:
[DllIport("User32")]
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);
            SetForegroundWindow(proc.MainWindowHandle);
            thisProcess.Kill();
            }
        }
    }
 
[edit]Typo: SetForgrondWindow for SetForegroundWindow - OriginalGriff[/edit]
  Permalink  
v2
Comments
darshan559 at 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 at 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) http://msdn.microsoft.com/en-us/library/awbckfbz.aspx

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 950
1 OriginalGriff 508
2 Abhinav S 233
3 thatraja 225
4 Emre Ataseven 200
0 Sergey Alexandrovich Kryukov 8,142
1 OriginalGriff 4,665
2 Peter Leow 3,774
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid