Dll import  
Author Message
Tammt





PostPosted: Visual C# General, Dll import Top

This is the DLL function:

unsigned int WINAPI GetAcquiredData(long* array, long size)

Is it correct if I do this in C#.net

[DllImport("Atmcd32d.dll")]

public static extern uint GetAcquiredData(ref int[] array, uint size);

It is cratched when I run this function in C# . However, I can run this function in VB6. Any one has idea

Thanks,

Tammy



Visual C#8  
 
 
Mike Danes





PostPosted: Visual C# General, Dll import Top

It does not work with ref, it not's a pointer to a pointer. You just need to pass the array:

[DllImport("Atmcd32d.dll")]

public static extern uint GetAcquiredData(int[] array, uint size);

Usage:

void foo()

{

byte[] data = new byte[100];

GetAcquiredData(data, data.Length);

}


 
 
Evan Mulawski





PostPosted: Visual C# General, Dll import Top

[DllImport(string filename)]

Is this what you need

Usually there is a method after the last bracket ( ] ) .

You can also add a reference to your project in the solution explorer by right clicking References.



 
 
Tammt





PostPosted: Visual C# General, Dll import Top

Thanks Mike, it helps!

Tammy


 
 
Sniper167





PostPosted: Visual C# General, Dll import Top

Yeah that's it but don't I have to reference something at the top with the "using" statement

 
 
Sniper167





PostPosted: Visual C# General, Dll import Top

Ok now I got it... thank you! Now I need to know how to use that dll in my form

[DllImport("ShellStyles.dll")]

private static extern void Example();



 
 
Friendly Dog





PostPosted: Visual C# General, Dll import Top

Usually I would create a wrapper class like

class Win32Calls

{

[DllImport("ShellStyles.dll")]

public static extern void Example();

}

Then use the class in your form



 
 
Evan Mulawski





PostPosted: Visual C# General, Dll import Top

If you know what ShellStyles.dll contains, then build a list of values. For example:

using System;

using System.Collections.Generic;

using System.Text;

using System.Runtime.InteropServices;

namespace Provectasoft_MC2007

{

public static class MemoryUtility

{

[DllImport("kernel32.dll")]

public static extern void GlobalMemoryStatus(out MemoryStatus stat);

public struct MemoryStatus

{

public uint Length; //Length of struct

public uint MemoryLoad; //Value from 0-100 represents memory usage

public uint TotalPhysical;

public uint AvailablePhysical;

public uint TotalPageFile;

public uint AvailablePageFile;

public uint TotalVirtual;

public uint AvailableVirtual;

}

}

}

 

This retreives the current system memory information.

Then, to use it in your form:

MemoryUtility.MemoryStatus memory;

MemoryUtility.GlobalMemoryStatus(out memory);

label1.Text = string.Format("{0} MB of physical memory", (memory.TotalPhysical / (1024.0 * 1024)));

 

Does this help



 
 
Sniper167





PostPosted: Visual C# General, Dll import Top

Yeah I understand that part I just meant that I want that style from the dll to be on my form. Like that dll that I have, I got from my computer its the dll that controls the color of the taskbar and style of the computer's UI. I wanted that to be integrated into my form so that my form will always be blue no matter what the users style is on his/her computer.

 
 
Evan Mulawski





PostPosted: Visual C# General, Dll import Top

Are you styling a toolstrip or statusbar control

 
 
Sniper167





PostPosted: Visual C# General, Dll import Top

Yeah that would help if I knew the functions it contained... Thank you for trying.

 
 
Sniper167





PostPosted: Visual C# General, Dll import Top

Toolstrip

 
 
Sniper167





PostPosted: Visual C# General, Dll import Top

Evan, could we talk through e-mail please I can send u my code and we can talk about it easier.

 
 
Evan Mulawski





PostPosted: Visual C# General, Dll import Top

Well, if you want to keep your entire form style in blue, try creating your own ToolStripRenderer class.

If you just retreive the values from ShellStyles.dll, it will just be the same as the Olive style, if that's what the user has enabled.

It won't just display blue, it's a global link library that reflects the system settings.

Try this:

public class CustomRenderer : ToolStripRenderer

{

protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)

{

LinearGradientBrush brush = new LinearGradientBrush(e.AffectedBounds, Color.DarkGray, Color.Black, 90);

e.Graphics.FillRectangle(brush, e.AffectedBounds);

brush.Dispose();

}

protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)

{

if (e.Item.Selected || e.Item.Pressed)

{

LinearGradientBrush brush = new LinearGradientBrush(e.Item.Bounds, Color.DarkBlue, Color.DarkGreen, 90);

e.Graphics.FillRectangle(brush, 0, 0, e.Item.Width, e.Item.Height);

}

}

protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)

{

e.Text.Color = Color.White;

base.OnRenderItemText(e);

}

//Then plug in the renderer. Make sure the above code is in a new class called CustomRenderer.cs

ToolStripManager.Renderer = new CustomRenderer();

Does this help



 
 
Evan Mulawski





PostPosted: Visual C# General, Dll import Top

Sure, my e-mail is



 
 
Evan Mulawski





PostPosted: Visual C# General, Dll import Top

You can also try KryptonComponents forms:

http://componentfactory.com/downloads.html

Download it from your e-mail.

Replace Form with KryptonForm after you add a reference to your solution.