This code was given to me by DiGiTaIErRoR on this forum.

I need to rewrite this in VB.NET code. Can anyone help.

I has been suggested to me that I can use PInvoke to call these apis. I wouldn't have thought that was a good idea if I want my code to be fully .net framework compliant.

What are your thoughts.

[code]Private Sub something()
Dim x As Long

Pal.palNumEntries = 10
Pal.palVersion = &H300 'defines our palette entries and type of palette

'define the colors in the palette
Pal.palPalEntry(1).peRed = 1
Pal.palPalEntry(1).peGreen = 2
Pal.palPalEntry(1).peBlue = 3

Pal.palPalEntry(2).peRed = 255
Pal.palPalEntry(2).peGreen = 255
Pal.palPalEntry(2).peBlue = 255

'When you've set the colors in the palette, you now do:

hPal = CreatePalette(Pal)

x = GetNearestPaletteIndex(hPal, vbRed)

'now to retieve the palette's 'approximate' of somecolor
Dim R As Long: R = Pal.palPalEntry(x).peRed
Dim g As Long: g = Pal.palPalEntry(x).peGreen
Dim b As Long: b = Pal.palPalEntry(x).peBlue

MsgBox R & " " & g & " " & b

x = GetNearestPaletteIndex(hPal, vbWhite)

'now to retieve the palette's 'approximate' of somecolor
R = Pal.palPalEntry(x).peRed
g = Pal.palPalEntry(x).peGreen
b = Pal.palPalEntry(x).peBlue

MsgBox R & " " & g & " " & b
end sub
[/Highlight]

from MSDN

GetNearestPaletteIndex
The GetNearestPaletteIndex function retrieves the index for the entry in the specified logical palette most closely matching a specified color value.

UINT GetNearestPaletteIndex(
HPALETTE hpal, // handle of logical color palette
COLORREF crColor // color to be matched
);