C#: Error calling the camera on the tablet of Microsoft Surface-win10 - camera

[DllImport("avicap32.dll")]
public static extern bool capGetDriverDescriptionA(short wDriver, byte[] lpszName, int cbName, byte[] lpszVer, int cbVer);
[DllImport("avicap32.dll")]
public static extern IntPtr capCreateCaptureWindowA(byte[] lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, int nID);
[DllImport("User32.dll")]
public static extern bool SendMessage(IntPtr hWnd, int wMsg, short wParam, int lParam);
[DllImport("User32.dll")]
public static extern bool SendMessage(IntPtr hWnd, int wMsg, bool wParam, int lParam);
public const int WM_USER = 0x400;
public const int WS_CHILD = 0x40000000;
public const int WS_VISIBLE = 0x10000000;
public const int WM_CAP_DRIVER_CONNECT = WM_USER + 10;
public const int WM_CAP_DRIVER_DISCONNECT = WM_USER + 11;
public const int WM_CAP_SET_PREVIEW = WM_USER + 50;
public const int WM_CAP_SET_PREVIEWRATE = WM_USER + 52;
byte[] lpszName = new byte[100];
byte[] lpszVer = new byte[100];
capGetDriverDescriptionA(0, lpszName, 100, lpszVer, 100);
IntPtr lwndC = capCreateCaptureWindowA(lpszName, WS_VISIBLE + WS_CHILD, 0, 0, mWidth, mHeight, mControlPtr, 0);
//When the program runs to the following code, a camera selection dialog box (Microsoft Camera Front/Microsoft Camera Rear) appears. After selecting any of them, the code in the if statement is not executed,and the camera cannot run normally. Can anyone help me? Why is this happening, thank you.
if (SendMessage(lwndC, VideoAPI.WM_CAP_DRIVER_CONNECT, 0, 0))
{
SendMessage(lwndC, WM_CAP_SET_PREVIEWRATE, 66, 0);
SendMessage(lwndC, WM_CAP_SET_PREVIEW, true, 0);
}

Related

Getting 0xC000041D crash in simple directX12 application

I have a simple Window class and I use a function for WM_PAINT that clears the render target view and presents the final image.so there's not much into it but I get a crash on line FLOAT clearColor[] = { 0.2f, 0.4f, 0.6f, 1.0f }; that says:0xC000041D: An unhandled exception was encountered during a user callback.
here's the window class:
class Win32Window : public WindowsWindow
{
public:
Win32Window(const WindowProps& props);
virtual ~Win32Window();
void OnUpdate() override;
unsigned int GetWidth() const override { return m_Data.Width; }
unsigned int GetHeight() const override { return m_Data.Height; }
void SetEventCallback(const EventCallbackFn& callback) override { m_Data.EventCallback = callback; }
void SetVSync(bool enabled) override;
bool IsVSync() const override;
virtual void* GetNativeWindow() const override { return m_Window; }
private:
HWND m_Window;
RECT m_WindowRect;
HINSTANCE m_hInst;
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
virtual void Init(const WindowProps& props);
virtual void Shutdown();
};
the definitions:
Win32Window::Win32Window(const WindowProps& props)
{
HZ_PROFILE_FUNCTION();
Init(props);
}
Win32Window::~Win32Window()
{
HZ_PROFILE_FUNCTION();
Shutdown();
}
void Win32Window::Init(const WindowProps& props)
{
m_hInst = GetModuleHandle(0);
m_Data.WideCharacterTitle = props.WideCharacterTitle;
m_Data.Width = props.Width;
m_Data.Height = props.Height;
HZ_CORE_INFO("Creating window {0} ({1}, {2})",props.StringTypeTitle, props.Width, props.Height);
WNDCLASSEXW windowClass = {};
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = &WndProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = m_hInst;
windowClass.hIcon = ::LoadIcon(m_hInst, NULL);
windowClass.hCursor = ::LoadCursor(NULL, IDC_ARROW);
windowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
windowClass.lpszMenuName = NULL;
windowClass.lpszClassName = m_Data.WideCharacterTitle;
windowClass.hIconSm = ::LoadIcon(m_hInst, NULL);
static ATOM atom = ::RegisterClassExW(&windowClass);
assert(atom > 0);
int screenWidth = ::GetSystemMetrics(SM_CXSCREEN);
int screenHeight = ::GetSystemMetrics(SM_CYSCREEN);
RECT windowRect = { 0, 0, static_cast<LONG>(m_Data.Width), static_cast<LONG>(m_Data.Height) };
::AdjustWindowRect(&windowRect, WS_OVERLAPPEDWINDOW, FALSE);
int windowWidth = windowRect.right - windowRect.left;
int windowHeight = windowRect.bottom - windowRect.top;
int windowX = std::max<int>(0, (screenWidth - windowWidth) / 2);
int windowY = std::max<int>(0, (screenHeight - windowHeight) / 2);
m_Window = ::CreateWindowExW(NULL, m_Data.WideCharacterTitle, m_Data.WideCharacterTitle, WS_OVERLAPPEDWINDOW, windowX, windowY, windowWidth, windowHeight, NULL, NULL, m_hInst, this);
assert(m_Window && "Failed to create window");
m_Context = GraphicsContext::Create(m_Window);
m_Context->Init();
::ShowWindow(m_Window, SW_SHOW);
::UpdateWindow(m_Window);
}
LRESULT Win32Window::MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_PAINT:
m_Context->RenderWindow();
break;
case WM_DESTROY:
::PostQuitMessage(0);
break;
default:
return ::DefWindowProcW(hwnd, message, wParam, lParam);
}
}
LRESULT Win32Window::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
Win32Window* instance;
if (message == WM_CREATE)
{
instance = (Win32Window*)(((LPCREATESTRUCT)lParam)->lpCreateParams);
instance->m_Window = hwnd;
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)instance);
}
else
{
instance = (Win32Window*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
}
if (instance)
{
return instance->MainWndProc(hwnd, message, wParam, lParam);
}
return ::DefWindowProcW(hwnd, message, wParam, lParam);
}
void Win32Window::Shutdown()
{
DestroyWindow(m_Window);
m_Window = nullptr;
}
void Win32Window::OnUpdate()
{
m_Context->Update();
}
void Win32Window::SetVSync(bool enabled)
{
m_Data.VSync = enabled;
}
bool Win32Window::IsVSync() const
{
return m_Data.VSync;
}
m_Context is coming from the parent class, And also WindowProps that has some data for initializing the window .definition of m_Context->RenderWindow():
m_CommnadQueue = D3D12Core::Get().GetCommandQueue(D3D12_COMMAND_LIST_TYPE_DIRECT);
auto m_CommandList = m_CommnadQueue->GetCommandList();
m_CurrentBackBufferIndex = m_SwapChain->GetCurrentBackBufferIndex();
auto m_BackBuffer = D3D12Core::Get().m_BackBuffers[m_CurrentBackBufferIndex];
auto m_RTVDescriptorSize = D3D12Core::Get().GetDevice()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
{
CD3DX12_RESOURCE_BARRIER barrier = CD3DX12_RESOURCE_BARRIER::Transition(m_BackBuffer.Get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET);
m_CommandList->ResourceBarrier(1, &barrier);
FLOAT clearColor[] = { 0.2f, 0.4f, 0.6f, 1.0f };
CD3DX12_CPU_DESCRIPTOR_HANDLE rtv(m_RTVDescriptorHeap->GetCPUDescriptorHandleForHeapStart(), m_CurrentBackBufferIndex, m_RTVDescriptorSize);
m_CommandList->ClearRenderTargetView(rtv, clearColor, 0, nullptr);
}
{
CD3DX12_RESOURCE_BARRIER barrier = CD3DX12_RESOURCE_BARRIER::Transition(m_BackBuffer.Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT);
m_CommandList->ResourceBarrier(1, &barrier);
m_CommandList->Close();
ID3D12CommandList* const commandLists[] =
{
m_CommandList.Get()
};
D3D12Core::Get().m_FenceValues[m_CurrentBackBufferIndex] = m_CommnadQueue->ExecuteCommandList(m_CommandList);
UINT syncInterval = m_VSync;
UINT presentFlags = m_TearingSupport && !m_VSync ? DXGI_PRESENT_ALLOW_TEARING : 0;
m_SwapChain->Present(syncInterval, presentFlags);
m_CommnadQueue->WaitForFenceValue(D3D12Core::Get().m_FenceValues[m_CurrentBackBufferIndex]);
}
If there is anything else that I should put in question pls tell me.You can shout at me for my dumbness if you want to but help me pls,thx.
EDIT:
debug layer:
#ifdef _DEBUG
ComPtr<ID3D12Debug> debugInterface;
if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugInterface))))
{
debugInterface->EnableDebugLayer();
}
#endif
WaitForFenceValue after every Present is an extremely slow way to render in DirectX 12. You should generally cue 2-3 frames to the GPU rather than forcing the GPU to stall every frame. It is also highly problematic to have your WndProc block, which is what happens here. Your WndProc should always complete quickly as many hundreds of messages are processed a second for most applications.
Usually Direct3D rendering is not done within WM_PAINT. For a number of examples of common render loops, see GitHub.

PInvoke - Issue while calling DJVU function from C# code. Attempted to read or write protected memory

UPDATE 3-4-15:11IS
As recommended by David modified PInvoke as below, this time I am getting different error "Unhandled exception of type System.ExecutionEngineException occurred in mscorlib.dll"
[DllImport("C:\\Program Files\\DJVULIBRE\\LIBDJVULIBRE.dll", CharSet=CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
private unsafe static extern int ddjvu_page_render(IntPtr page, ddjvu_render_mode_t mode, ref ddjvu_rect_t pagerect,
ref ddjvu_rect_t renderrect,
IntPtr pixelformat,
uint rowsize,
[Out][MarshalAs(UnmanagedType.LPArray)]byte[] imagebuffer);
Thanks David for your valuable time, I think is close to a fix.
HISTORY
I know there are many questions in this subject but none of them help to resolve the issue I am currently facing.
Below is the API function in C Language
DDJVUAPI int
ddjvu_page_render(ddjvu_page_t *page,
const ddjvu_render_mode_t mode,
const ddjvu_rect_t *pagerect,
const ddjvu_rect_t *renderrect,
const ddjvu_format_t *pixelformat,
unsigned long rowsize,
char *imagebuffer );
Below is the PInvoke signature of C Function added in .NET code
[DllImport("C:\\Program Files\\DJVULIBRE\\LIBDJVULIBRE.dll", CharSet=CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
private unsafe static extern int ddjvu_page_render(IntPtr page, ddjvu_render_mode_t mode, IntPtr pagerect,
IntPtr renderrect,
IntPtr pixelformat,
ulong rowsize,
[Out][MarshalAs(UnmanagedType.LPArray)]byte[] imagebuffer);
Below is how I am calling this function in the c# code
byte* buffer = (byte *)Memory.Alloc(nSize);
try
{
IntPtr ptr1 = (IntPtr)Memory.Alloc(Marshal.SizeOf(prect));
Marshal.StructureToPtr(prect, ptr1, false);
IntPtr ptr2 = (IntPtr)Memory.Alloc(Marshal.SizeOf(rrect));
Marshal.StructureToPtr(rrect, ptr2, false);
byte[] array = new byte[nSize];
fixed (byte* p = array) Memory.Copy(buffer, p, nSize);
ddjvu_page_render(page, ddjvu_render_mode_t.DDJVU_RENDER_MASKONLY, ptr1, ptr2, fmt, (ulong)stride, array);
}
finally
{
Memory.Free(buffer);
}
call to ddjvu_page_render in above code is throwing "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Prior to this post I must have tried all the option could find in various blogs.
Appreciate any help, is almost a day I am clueless, your timely help could save my job
UPDATE 3-4-15:7:44IS
This code is using DJVULibre
UPDATE 3-4-15:8:35IS
Here is the code I have in Form Load
ctx = ddjvu_context_create(System.AppDomain.CurrentDomain.FriendlyName);
if (ctx != null)
{
string djFile = "C:\\Users\\rammohan.chavakula\\Documents\\eiasample.djvu";
doc = ddjvu_document_create_by_filename(ctx, djFile, 100);
if (doc != null)
{
while (ddjvu_job_status(ddjvu_document_job(doc)) >= ddjvu_status_t.DDJVU_JOB_OK)
SpinDdjvuMessageLoop(ctx, true);
int pageCount = ddjvu_document_get_pagenum(doc);
mediaboxes = new Rectangle[pageCount];
for (int i = 0; i < pageCount; i++)
{
ddjvu_status_t status;
ddjvu_pageinfo_t info = new ddjvu_pageinfo_t();
while ((status = ddjvu_document_get_pageinfo_imp(doc, i, ref info, (uint)System.Runtime.InteropServices.Marshal.SizeOf(info))) < ddjvu_status_t.DDJVU_JOB_OK)
SpinDdjvuMessageLoop(ctx, true);
if (status != ddjvu_status_t.DDJVU_JOB_OK)
continue;
mediaboxes[i] = new Rectangle(0, 0, info.width / info.dpi,
info.height / info.dpi);
}
}
ddjvu_context_release(ctx);
}
In OnPaint function I have this below code
if (doc == null)
{
base.OnPaint(e);
return;
}
Rectangle pageRc = PageMediabox(1);
Rectangle screen = Transform(pageRc, 1, zoom, rotation, false);
Rectangle full = Transform(PageMediabox(1), 1, zoom, rotation, false);
full.Intersect(screen);
IntPtr page = ddjvu_page_create_by_pageno(doc, 1);
if (page == null )
{
base.OnPaint(e);
return;
}
int rotation4 = (((-rotation / 90) % 4) + 4) % 4;
ddjvu_page_set_rotation(page, (ddjvu_page_rotation_t)rotation4);
while (ddjvu_job_status(ddjvu_page_job(page)) >= ddjvu_status_t.DDJVU_JOB_OK)
SpinDdjvuMessageLoop(ctx, true);
if (ddjvu_job_status(ddjvu_page_job(page)) >= ddjvu_status_t.DDJVU_JOB_FAILED)
{
base.OnPaint(e);
return;
}
IntPtr fmt = ddjvu_format_create(ddjvu_format_style_t.DDJVU_FORMAT_BGR24, 0, (UIntPtr)null);
ddjvu_format_set_row_order(fmt, /* top_to_bottom */1);
ddjvu_rect_t prect = new ddjvu_rect_t(full.X, full.Y, (uint)full.Width, (uint)full.Height);
ddjvu_rect_t rrect = new ddjvu_rect_t(screen.X, 2 * full.Y + screen.Y + full.Height - screen.Height, (uint)screen.Width, (uint)screen.Height);
int stride = ((screen.Width * 3 + 3) / 4) * 4;
//byte tmp;
////ScopedMem<char> bmpData(SAZA(char, stride * (screen.dy + 5)));
//for (int y = 0; y < rrect.h; y++) {
// int step_y = y * SCREEN_WIDTH;
// for (int x=0; x < rrect.w; x++) {
// tmp = (byte)((imagebuf[x + step_y] >> 5) << 5);
// }
//}
int rowsize = mediaboxes[0].Width * 3;
int nSize = rowsize * (mediaboxes[0].Height) * 10;
unsafe
{
byte* buffer = (byte *)Memory.Alloc(nSize);
try
{
IntPtr ptr1 = (IntPtr)Memory.Alloc(Marshal.SizeOf(prect));
Marshal.StructureToPtr(prect, ptr1, false);
IntPtr ptr2 = (IntPtr)Memory.Alloc(Marshal.SizeOf(rrect));
Marshal.StructureToPtr(rrect, ptr2, false);
byte[] array = new byte[nSize];
fixed (byte* p = array) Memory.Copy(buffer, p, nSize);
ddjvu_page_render(page, ddjvu_render_mode_t.DDJVU_RENDER_MASKONLY, ptr1, ptr2, fmt, (ulong)stride, array);
}
finally
{
Memory.Free(buffer);
}
ddjvu_page_render should return arbitrary data of page which is to be rendered in a given rectangle area. Once after that I should be able to create image from arbitrary data & display in the screen
Here's how I would write the p/invoke:
[DllImport(dllname, CharSet=CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
private static extern int ddjvu_page_render(
[In] IntPtr page,
[In] ddjvu_render_mode_t mode,
[In] ref ddjvu_rect_t pagerect,
[In] ref ddjvu_rect_t renderrect,
[In] ref ddjvu_format_t pixelformat,
[In] uint rowsize,
[Out] byte[] imagebuffer
);
Note that I've stopped using unsafe, and am letting the marshaler handle the structs automatically.
There are quite a few assumptions here that I cannot verify:
The calling convention. It might not be cdecl. The C++ header will would have the definitive answer.
The first parameter is a void* handle type, I presume.
ddjvu_render_mode_t is an enum that you have translated correctly.
The three ref parameters are structs, passed by reference. I cannot check that you have translated them correctly.
Calling this function would be something like this:
byte[] imagebuffer = new byte[nSize];
int retval = ddjvu_page_render(
page,
ddjvu_render_mode_t.DDJVU_RENDER_MASKONLY,
ref prect,
ref rrect,
ref fmt,
(uint)stride,
imagebuffer
);
if (retval != ??)
// handle error
This is quite a broad brush answer. I hope it points you in the right direction. I don't think that all your problems will be solved by this.

Application crashes when using hooked functions

I've been trying to hook a few winapi functions, e.g. DrawText, TextOut, ExtTextOut using detours. In case of injecting my dll into windows calculator the hooked functions are working fine until i press a button on the calculator, which then causes a crash. Injecting my dll into other processes causes similar behaviour. All hooks are working fine until i trigger certain actions like opening the new file dialog in notepad.
I've tested my dll on 32 and 64 bit windows 7 systems, both shows the same behaviour.
Any ideas on what could be causing the problem?
My dll:
main.cpp
#include <Windows.h>
#include <detours.h>
#include "hookedFunctions.h"
BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{
switch (ul_reason_for_call){
case DLL_PROCESS_ATTACH:
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)pDrawTextW, myDrawTextW);
DetourAttach(&(PVOID&)pDrawTextA, myDrawTextA);
DetourAttach(&(PVOID&)pExtTextOutW, myExtTextOutW);
DetourAttach(&(PVOID&)pExtTextOutA, myExtTextOutA);
DetourAttach(&(PVOID&)pTextOutW, myTextOutW);
DetourAttach(&(PVOID&)pTextOutA, myTextOutA);
DetourAttach(&(PVOID&)myPolyTextOutW, myPolyTextOutW);
DetourAttach(&(PVOID&)myPolyTextOutA, myPolyTextOutA);
if(DetourTransactionCommit() == NO_ERROR)
OutputDebugStringA("Detoured successfully");
break;
case DLL_PROCESS_DETACH:
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)pDrawTextW, myDrawTextW);
DetourDetach(&(PVOID&)pDrawTextA, myDrawTextA);
DetourDetach(&(PVOID&)pExtTextOutW, myExtTextOutW);
DetourDetach(&(PVOID&)pExtTextOutA, myExtTextOutA);
DetourDetach(&(PVOID&)pTextOutW, myTextOutW);
DetourDetach(&(PVOID&)pTextOutA, myTextOutA);
DetourDetach(&(PVOID&)myPolyTextOutW, myPolyTextOutW);
DetourDetach(&(PVOID&)myPolyTextOutA, myPolyTextOutA);
if(DetourTransactionCommit() == NO_ERROR)
OutputDebugStringA("Detoured successfully");
break;
}
return TRUE;
}
hookedFunctions.h
#pragma once
#include <Windows.h>
// Declare function pointers to original Windows API functions
extern int (WINAPI *pDrawTextW)(HDC, LPCTSTR, int, LPRECT, UINT);
extern int (WINAPI *pDrawTextA)(HDC, LPCSTR, int, LPRECT, UINT);
extern BOOL (WINAPI *pTextOutW)(HDC, int, int, LPCTSTR, int);
extern BOOL (WINAPI *pTextOutA)(HDC, int, int, LPCSTR, int);
extern BOOL (WINAPI *pExtTextOutW)(HDC, int, int, UINT, const RECT*, LPCTSTR, UINT, const INT*);
extern BOOL (WINAPI *pExtTextOutA)(HDC, int, int, UINT, const RECT*, LPCSTR, UINT, const INT*);
extern BOOL (WINAPI *pPolyTextOutW)(HDC, const POLYTEXTW* , int);
extern BOOL (WINAPI *pPolyTextOutA)(HDC, const POLYTEXTA* , int);
// Declare our custom functions which are used to override the original Windows API functions
int myDrawTextW(HDC, LPCTSTR, int, LPRECT, UINT);
int myDrawTextA(HDC, LPCSTR, int, LPRECT, UINT);
BOOL myTextOutW(HDC, int, int, LPCTSTR, int);
BOOL myTextOutA(HDC, int, int, LPCSTR, int);
BOOL myExtTextOutW(HDC, int, int, UINT, const RECT*, LPCTSTR , UINT, const INT*);
BOOL myExtTextOutA(HDC, int, int, UINT, const RECT*, LPCSTR , UINT, const INT*);
BOOL myPolyTextOutW(HDC, const POLYTEXTW*, int);
BOOL myPolyTextOutA(HDC, const POLYTEXTA*, int);
hookedFunctions.cpp
#include "hookedFunctions.h"
// Create and initialize function pointers to original Windows API functions
int (WINAPI *pDrawTextW)(HDC, LPCTSTR, int, LPRECT, UINT) = DrawTextW;
int (WINAPI *pDrawTextA)(HDC, LPCSTR, int, LPRECT, UINT) = DrawTextA;
BOOL (WINAPI *pTextOutW)( HDC, int, int, LPCTSTR, int) = TextOutW;
BOOL (WINAPI *pTextOutA)(HDC, int, int, LPCSTR, int) = TextOutA;
BOOL (WINAPI *pExtTextOutW)(HDC, int, int, UINT, const RECT*, LPCTSTR, UINT, const INT*) = ExtTextOutW;
BOOL (WINAPI *pExtTextOutA)(HDC, int, int, UINT, const RECT*, LPCSTR, UINT, const INT*) = ExtTextOutA;
BOOL (WINAPI *pPolyTextOutW)(HDC, const POLYTEXTW* , int) = PolyTextOutW;
BOOL (WINAPI *pPolyTextOutA)(HDC, const POLYTEXTA* , int) = PolyTextOutA;
// Custom versions of the Windows API functions, having the same parameters,
// return type, and calling convention as the versions provided by the OS.
int myDrawTextW(HDC hDC, LPCTSTR lpchText, int nCount, LPRECT lpRect, UINT uFormat)
{
OutputDebugString(lpchText);
return pDrawTextW(hDC, lpchText, nCount, lpRect, uFormat);
}
int myDrawTextA(HDC hDC, LPCSTR lpchText, int nCount, LPRECT lpRect, UINT uFormat)
{
OutputDebugStringA(lpchText);
return pDrawTextA(hDC, lpchText, nCount, lpRect, uFormat);
}
BOOL myTextOutW(HDC hdc, int nXStart, int nYStart, LPCTSTR lpString, int cchString)
{
OutputDebugString(lpString);
return pTextOutW(hdc, nXStart, nYStart, lpString, cchString);
}
BOOL myTextOutA(HDC hdc, int nXStart, int nYStart, LPCSTR lpString, int cchString)
{
OutputDebugStringA(lpString);
return pTextOutA(hdc, nXStart, nYStart, lpString, cchString);
}
BOOL myExtTextOutW(HDC hdc, int X, int Y, UINT fuOptions, const RECT *lprc,
LPCTSTR lpString, UINT cbCount, const INT *lpDx)
{
OutputDebugString(lpString);
return pExtTextOutW(hdc, X, Y, fuOptions, lprc, lpString, cbCount, lpDx);
}
BOOL myExtTextOutA(HDC hdc, int X, int Y, UINT fuOptions, const RECT *lprc,
LPCSTR lpString, UINT cbCount, const INT *lpDx)
{
OutputDebugStringA(lpString);
return pExtTextOutA(hdc, X, Y, fuOptions, lprc, lpString, cbCount, lpDx);
}
BOOL myPolyTextOutW(HDC hdc, const POLYTEXTW *pptxt, int cStrings)
{
OutputDebugString(pptxt->lpstr);
return pPolyTextOutW(hdc, pptxt, cStrings);
}
BOOL myPolyTextOutA(HDC hdc, const POLYTEXTA *pptxt, int cStrings)
{
OutputDebugStringA(pptxt->lpstr);
return pPolyTextOutA(hdc, pptxt, cStrings);
}
Problem solved - I forgot to add WINAPI to my functions. Headers must look like this: int WINAPI myDrawTextW(HDC, LPCTSTR, int, LPRECT, UINT);

Compact Framework - Keep modal window in front of windows bar after closing CaptureCameraDialog

I am working on a windows mobile application. I have created a wizard that uses a modal window so that the windows bar is hidden. One of the wizard stages has requires a picture to be taken. After launching the CaptureCameraDialog, the windows bar appears and remains even after the CaptureCameraDialog is closed. Is there any way to bring my dialog form back in front of the windows bar?
I eventually managed to find some code on the web that did what I was looking for. Here it is:
public partial class myForm : Form
{
public myForm()
{
InitializeComponent();
this.GotFocus += delegate(object sender, EventArgs args)
{
//var intPtr = FindWindow("CaptureReturnForm", "");
SetForegroundWindow(GetFocus());
bool result = SHFullScreen(GetFocus(), SHFS_HIDESTARTICON |
SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON); // 0x0020);
};
}
[DllImport("coredll.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("coredll.dll", EntryPoint = "SetForegroundWindow")]
private static extern int SetForegroundWindow(IntPtr hWnd);
[DllImport("coredll.dll")]
internal static extern IntPtr GetFocus();
[DllImport("aygshell.dll")]
internal static extern bool SHFullScreen(IntPtr hWnd, uint dwState);
const uint SHFS_SHOWTASKBAR = 0x1;
const uint SHFS_HIDETASKBAR = 0x2;
const uint SHFS_SHOWSIPBUTTON = 0x4;
const uint SHFS_HIDESIPBUTTON = 0x8;
const uint SHFS_SHOWSTARTICON = 0x10;
const uint SHFS_HIDESTARTICON = 0x20;
const int HWND_TOPMOST = -1;
const int HWND_NOTOPMOST = -2;
const uint SWP_SHOWWINDOW = 0x40;
const uint SM_CXSCREEN = 0x0;
const uint SM_CYSCREEN = 0x1;
private const int HHTASKBARHEIGHT = 26;
}

Is there a way to hide 'System.Windows.Forms.ListBox()' border?

Is there a way to hide System.Windows.Forms.ListBox() border?
If anyone is interested... this seems to work. Another thumbs down for the compact framework.
public Form1()
{
InitializeComponent();
ShowBorder(listView1.Handle, false);
}
private void ShowBorder(IntPtr handle, bool bShow)
{
int style = GetWindowLong(handle, GWL_STYLE);
if (bShow)
{
style |= WS_BORDER;
}
else
{
style &= ~WS_BORDER;
}
SetWindowLong(handle, GWL_STYLE, style);
SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
}
const int GWL_STYLE = -16;
const int WS_BORDER = 0x00800000;
const int SWP_NOSIZE = 0x1;
const int SWP_NOMOVE = 0x2;
const int SWP_FRAMECHANGED = 0x20;
[DllImport("coredll.dll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("coredll.dll")]
private extern static void SetWindowLong(IntPtr hwnd,
int nIndex, int dwNewLong);
[DllImport("coredll.dll")]
private static extern bool SetWindowPos(IntPtr hwnd,
IntPtr hWndInsertAfter,
int x, int y,
int cx, int cy, int uflags);