Native C++ CreateDIBSection in VB.NET

I want to rewrite the C++ code to VB.NET, but does not succeed.

I don't understand, how can I make int *pixels in VB.NET.

And don't understand how can I pass an array to CreateDIBSection.

The simplified C++ code:

#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <cmath>

const int width = 375;
const int height = 375;
HANDLE hTickThread;
HWND hwnd;
HDC hdcMem;
void MakeSurface(HWND hwnd) {
  bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
  bmi.bmiHeader.biWidth = width;
  bmi.bmiHeader.biHeight = -height;
  bmi.bmiHeader.biPlanes = 1;
  bmi.bmiHeader.biBitCount = 32;
  bmi.bmiHeader.biCompression = 0;

  HDC hdc = GetDC(hwnd);
  int *pixels;

  hbmp = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&pixels, NULL, 0);

  for (int i = 0; i < 80000; ++i) {
    pixels[i] = 13107200;

  ShowWindow(hwnd, SW_SHOW);
  hdcMem = CreateCompatibleDC(hdc);
  SelectObject(hdcMem, hbmp);
  BitBlt(hdc, 0, 0, width, height, hdcMem, 0, 0, SRCCOPY);

  HWND hwnd,
  UINT msg,
  WPARAM wParam,
  LPARAM lParam)
  switch (msg) {
  case WM_CREATE:
    return DefWindowProc(hwnd, msg, wParam, lParam);
  return 0;
int WINAPI WinMain(
  HINSTANCE hInstance,
  HINSTANCE hPrevInstance,
  LPSTR lpCmdLine,
  int nShowCmd)
  MSG msg;
  // Init wc
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 0;
  wc.cbSize = sizeof(WNDCLASSEX);
  wc.hbrBackground = CreateSolidBrush(0);
  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  wc.hInstance = hInstance;
  wc.lpfnWndProc = WndProc;
  wc.lpszClassName = "animation_class";
  wc.lpszMenuName = NULL; = 0;
  // Register wc
  if (!RegisterClassEx(&wc)) {
    MessageBox(NULL, "Failed to register window class.", "Error", MB_OK);
    return 0;
  // Make window
  hwnd = CreateWindowEx(WS_EX_APPWINDOW,"animation_class","Animation",WS_MINIMIZEBOX | WS_SYSMENU | WS_POPUP | WS_CAPTION,300, 200, width, height,      NULL, NULL, hInstance, NULL);
  RECT rcClient, rcWindow;
  POINT ptDiff;
  // Get window and client sizes
  GetClientRect(hwnd, &rcClient);
  GetWindowRect(hwnd, &rcWindow);
  // Find offset between window size and client size
  ptDiff.x = (rcWindow.right - rcWindow.left) - rcClient.right;
  ptDiff.y = (rcWindow.bottom - - rcClient.bottom;
  // Resize client
  MoveWindow(hwnd, rcWindow.left,, width + ptDiff.x, height + ptDiff.y, false);
  while (GetMessage(&msg, 0, 0, NULL) > 0) {
  return 0;

The code, but not working:

Imports System.Runtime.InteropServices

Public Class Form1
    Public Shared hbmp As System.IntPtr
    Public Shared hTickThread As System.IntPtr
    Public Shared hwnd As System.IntPtr
    Public Shared hdcMem As System.IntPtr
    Public Const _width As Integer = 375
    Public Const _height As Integer = 375
    Public Const SW_SHOW As Integer = 5
    Public Const DIB_RGB_COLORS As Integer = 0
    Public Const WM_CREATE As Integer = 1
    Public Const SRCCOPY As Integer = 13369376

    Public Shared Sub MakeSurface(ByVal hwnd As System.IntPtr)
        Dim bmi As New BITMAPINFO
        bmi.bmiHeader_biSize = Marshal.SizeOf(GetType(BITMAPINFO))
        bmi.bmiHeader_biWidth = _width
        bmi.bmiHeader_biHeight = -_height
        bmi.bmiHeader_biPlanes = 1
        bmi.bmiHeader_biBitCount = 32
        bmi.bmiHeader_biCompression = 0
        Dim hdc As System.IntPtr = GetDC(hwnd)

        Dim pixels() As Integer
        hbmp = CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, pixels, Nothing, 0)
        For i As Integer = 0 To 79999
            pixels(i) = 13107200
        Next i

        ShowWindow(hwnd, SW_SHOW)
        hdcMem = CreateCompatibleDC(hdc)
        SelectObject(hdcMem, hbmp)
        BitBlt(hdc, 0, 0, _width, _height, hdcMem, 0, 0, SRCCOPY)
    End Sub

    <DllImport("gdi32.dll", ExactSpelling:=True, SetLastError:=True)>
    Private Shared Function CreateDIBSection(ByVal hdc As IntPtr, ByRef pbmi As BITMAPINFO, ByVal iUsage As UInteger, ByVal ppvBits As Integer, ByVal hSection As IntPtr, ByVal dwOffset As UInteger) As IntPtr
    End Function

    Protected Overrides Sub WndProc(ByRef m As Message)
        Select Case m.Msg
            Case WM_CREATE
        End Select
    End Sub

    <DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)>
    Public Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
    End Function
    <DllImport("gdi32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)>
    Public Shared Function SelectObject(ByVal hDC As IntPtr, ByVal hObject As IntPtr) As IntPtr
    End Function
    <DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=False)>
    Public Shared Function GetDC(ByVal hWnd As IntPtr) As IntPtr
    End Function
<DllImport("gdi32.dll", CharSet:=CharSet.Auto, EntryPoint:="CreateCompatibleDC", ExactSpelling:=True, SetLastError:=True)>
Public Shared Function CreateCompatibleDC(ByVal hDC As IntPtr) As IntPtr
End Function
    <DllImport("gdi32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)>
    Public Shared Function BitBlt(ByVal hDC As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As IntPtr, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Boolean
    End Function
    Public Structure BITMAPINFO
        Public bmiHeader_biSize As Integer
        Public bmiHeader_biWidth As Integer
        Public bmiHeader_biHeight As Integer
        Public bmiHeader_biPlanes As Short
        Public bmiHeader_biBitCount As Short
        Public bmiHeader_biCompression As Integer
        Public bmiHeader_biSizeImage As Integer
        Public bmiHeader_biXPelsPerMeter As Integer
        Public bmiHeader_biYPelsPerMeter As Integer
        Public bmiHeader_biClrUsed As Integer
        Public bmiHeader_biClrImportant As Integer
        Public bmiColors_rgbBlue As Byte
        Public bmiColors_rgbGreen As Byte
        Public bmiColors_rgbRed As Byte
        Public bmiColors_rgbReserved As Byte
    End Structure

End Class

I use VB2015 with .NET 2.0.

Thanks for the help.

I get the "It looks like your post is mostly code; please add some more details." message. I write this for I can send this question.