Click here to Skip to main content
15,913,101 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
QuestionSTL vector, search for a sequence Pin
kaminem13-Apr-09 22:16
kaminem13-Apr-09 22:16 
AnswerRe: STL vector, search for a sequence Pin
Stuart Dootson14-Apr-09 22:46
professionalStuart Dootson14-Apr-09 22:46 
AnswerRe: STL vector, search for a sequence Pin
Stephen Hewitt15-Apr-09 0:58
Stephen Hewitt15-Apr-09 0:58 
GeneralRe: STL vector, search for a sequence Pin
Stuart Dootson16-Apr-09 20:34
professionalStuart Dootson16-Apr-09 20:34 
GeneralRe: STL vector, search for a sequence Pin
Stephen Hewitt19-Apr-09 4:43
Stephen Hewitt19-Apr-09 4:43 
QuestionAtlAxAttachControl - An outgoing call cannot be made since the application is dispatching an input-synchronous call. Pin
bfoo759-Apr-09 13:19
bfoo759-Apr-09 13:19 
AnswerRe: AtlAxAttachControl - An outgoing call cannot be made since the application is dispatching an input-synchronous call. Pin
Stuart Dootson14-Apr-09 22:14
professionalStuart Dootson14-Apr-09 22:14 
GeneralRe: AtlAxAttachControl - An outgoing call cannot be made since the application is dispatching an input-synchronous call. Pin
bfoo7521-Apr-09 11:07
bfoo7521-Apr-09 11:07 
Its a single threaded app but I think you might have something on the apartment model. I'm using this as a control inside a WIN32 window. The odd thing is that the FlashViewer::Init still throws the same error even if its executed before the WIN32 window is declared. The other strange thing is that this code executes if its included on its own like this:

#include <string>
#include <windows.h>
#include <exdisp.h>
#include <mshtmlc.h>

#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>

using std::string;

#import "PROGID:ShockwaveFlash.ShockwaveFlash" no_namespace raw_interfaces_only

typedef HRESULT (WINAPI *LPAtlAxWinInit) ();
typedef HRESULT (WINAPI *LPAtlAxGetControl)(HWND hwnd, IUnknown** unk);


int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmd, int show)
{
	LPAtlAxWinInit AtlAxWinInit3 = (LPAtlAxWinInit)GetProcAddress(LoadLibrary("atl"), "AtlAxWinInit");
	LPAtlAxGetControl AtlAxGetControl3 = (LPAtlAxGetControl)GetProcAddress(LoadLibrary("atl"), "AtlAxGetControl");

	MSG msg;
	HRESULT hr = AtlAxWinInit3();

	HWND hwnd = CreateWindow("AtlAxWin", "", WS_VISIBLE|WS_POPUP, 0, 0, 1024, 768, 0, 0, 0, 0);

	IShockwaveFlash* flash = 0;
	IViewObject* view = 0;

	hr = CoCreateInstance(__uuidof(ShockwaveFlash), 0, CLSCTX_ALL, __uuidof(IShockwaveFlash), (void **)&flash);
	hr = flash->put_WMode(L"transparent");
	hr = flash->put_Loop(true);
	

	hr = AtlAxAttachControl(flash, hwnd, NULL);
	hr = flash->put_Movie(L"c:\\FrontEnd.swf");
	hr = flash->QueryInterface(__uuidof(IViewObject), (void **) &view);

	long pVal = -1;
	flash->get_ReadyState(&pVal);

	BSTR val = L"Null", var = L"GetLastButton";
	string cval;

	while(GetMessage(&msg, 0, 0, 0) && flash)
	{
		hr = flash->CallFunction(L"<invoke name=\"GetLastButton\" returntype=\"string\"></invoke>" , &val);
		cval = _com_util::ConvertBSTRToString(val);
		
		if (cval.compare("<string>btnQuit</string>") == 0 )
		{
			PostMessage(hwnd, WM_QUIT, NULL, NULL); 
		}
		DispatchMessage(&msg);
	}
};


I tried using OleInitialize(NULL); at the start of the INIT function which is supposed to call CoInitializeEx with COINIT_APARTMENTTHREADED. But I still got the same problem.

Heres my shell for the windows app (excuse the amount of code):

WIN32APP.H

#define WIN32_LEAN_AND_MEAN

#include <windows.h>

#pragma once

#define SCREEN_WIDTH	1024
#define SCREEN_HEIGHT	768
#define COLOR_DEPTH		32

#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

class Win32App
{
public:
	Win32App()	{	};
	~Win32App()	{	};
	void Start(HINSTANCE hInst, bool isFullscreen);
	char const * Title;
	char const * ClassName;
	bool isFullscreen;

	static HINSTANCE hInst;
	static HWND hWnd;
private:
	//Windows Requirements
	WNDCLASS localWndClass;
	static LRESULT CALLBACK WindowsProcedure(HWND hwnd, unsigned int message, WPARAM wParam, LPARAM lParam);
protected:
	virtual void PreInitialize() 	{	};
	virtual void PostInitialize() 	{	};
	virtual void Main() 			{	};
	virtual void CleanUp()			{	};

	void StartMessagePump();
	void Quit()
	{
		PostMessage(hWnd, WM_QUIT, 0, 0);
	}
};

HINSTANCE Win32App::hInst;
HWND Win32App::hWnd;

void Win32App::Start(HINSTANCE hInst, bool isFullscreen)
{
	this->hInst = hInst;
	
	this->Title = "Win32App";
	this->ClassName = "Win32";

	this->isFullscreen = isFullscreen;

	this->PreInitialize();

	//Register the windows class
	localWndClass.style = 0;
	localWndClass.lpfnWndProc = WindowsProcedure;
	localWndClass.cbClsExtra = 0;
	localWndClass.cbWndExtra = 0;
	localWndClass.hInstance = this->hInst;
	localWndClass.hIcon = 0;
	localWndClass.hCursor = LoadCursor(0, IDC_ARROW);

	localWndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
	localWndClass.lpszMenuName = 0;
	localWndClass.lpszClassName = ClassName;
	
	RegisterClass(&localWndClass);

	//Create The Window
	if (!isFullscreen)
		this->hWnd = CreateWindow(
			this->ClassName,
			this->Title,
			WS_OVERLAPPEDWINDOW,
			CW_USEDEFAULT,
			CW_USEDEFAULT,
			CW_USEDEFAULT,
			CW_USEDEFAULT,
			NULL,
			NULL,
			hInst,
			NULL);
	else
		this->hWnd = CreateWindow(
			this->ClassName,
			this->Title,
			WS_EX_TOPMOST | WS_POPUP,
			0,
			0,
			SCREEN_WIDTH,
			SCREEN_HEIGHT,
			NULL,
			NULL,
			hInst,
			NULL);

	ShowWindow(this->hWnd, 1);
	UpdateWindow(this->hWnd);

	this->PostInitialize();//----------------------------------CALLS THE DDINITIALIZE() FUNCTION-------------------------

	StartMessagePump();
}

LRESULT CALLBACK Win32App::WindowsProcedure(HWND hwnd, unsigned int message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_DESTROY:
		{
		PostQuitMessage(0);
		return 0;
		} break;
	}
	return DefWindowProc(hwnd, message, wParam, lParam);
}
void Win32App::StartMessagePump()
{
	MSG msg;
	DWORD startTime;

	while (true)
	{
		startTime = GetTickCount();
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if (msg.message == WM_QUIT)
				break;

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		if(KEY_DOWN(VK_ESCAPE))
			PostMessage(hWnd, WM_QUIT, 0, 0);
		this->Main();
		//while ((GetTickCount() - startTime) < 25);
	}
	this->CleanUp();
	this->~Win32App();
}

DDAPP.H
#pragma once
#pragma comment (lib, "ddraw.lib")
#pragma comment (lib, "dxguid.lib")

#include <ddraw.h>
#include "Win32App.h"

#define INIT_DXSTRUCT(dxs) {ZeroMemory(&dxs, sizeof(dxs)); dxs.dwSize = sizeof(dxs);}

class DDApp : public Win32App
{
public:
	DDApp()
	{
	}
	static void LoadBitmap(LPDIRECTDRAWSURFACE7 lpdds, int xDest, int yDest, LPCSTR Filename);
	void Restore();
protected:
	//DD specific functions
	virtual void DDInitialize() {} //-------------------CALLS THE FlashViewer::Init() function---------------
	virtual void Update() {}
	virtual void RenderFrame() {}
	virtual void Release() {}
	//Overridden functions
	virtual void PostInitialize();//--------------------OVERLOADED FROM WIN32APP-----------------------------
	virtual void Main();
	virtual void CleanUp();
	
	//Internally Accessable variables
	LPDIRECTDRAW7 lpDD7;
	
	LPDIRECTDRAWSURFACE7 lpddsPrimary;
	LPDIRECTDRAWSURFACE7 lpddsBack;

	DDSURFACEDESC2 ddsd;
};

void DDApp::PostInitialize()//--------------------OVERLOADED FROM WIN32APP-----------------------------
{
	CoInitialize(NULL);
	CoCreateInstance(CLSID_DirectDraw, NULL, CLSCTX_ALL, IID_IDirectDraw7, (void**)&lpDD7);
	lpDD7->Initialize(NULL);
	if (isFullscreen)
		lpDD7->SetCooperativeLevel(hWnd, DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
	else
		lpDD7->SetCooperativeLevel(hWnd, DDSCL_NORMAL);
	lpDD7->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, COLOR_DEPTH, 0, 0);

	lpddsPrimary = NULL;
	lpddsBack = NULL;

	INIT_DXSTRUCT(ddsd);

	ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
	ddsd.dwBackBufferCount = 1;
	ddsd.ddsCaps.dwCaps =	DDSCAPS_PRIMARYSURFACE |	//Primary Surface
							DDSCAPS_COMPLEX |			//Chained backbuffer
							DDSCAPS_FLIP |				//Allow page flipping
							DDSCAPS_VIDEOMEMORY;		//Create in video memory

	lpDD7->CreateSurface(&ddsd, &lpddsPrimary, NULL);  

	ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
	lpddsPrimary->GetAttachedSurface(&ddsd.ddsCaps, &lpddsBack);
	DDInitialize();     //----------------------------CALLS THE FlashViewer::Init() function-----------------------------------
}
void DDApp::Main()
{
	Update();
	RenderFrame();
	HRESULT r = lpddsPrimary->Flip(NULL, DDFLIP_WAIT);
}
void DDApp::CleanUp()
{
	Release();
	lpddsBack->Release();
	lpddsPrimary->Release();
	lpDD7->Release();
}
void DDApp::LoadBitmap(LPDIRECTDRAWSURFACE7 lpdds, int xDest, int yDest, LPCSTR Filename)
{
	HDC hSrcDC;
	HDC hDestDC;
	HBITMAP hbitmap;
	BITMAP bmp;
	int nHeight, nWidth;

	hbitmap = (HBITMAP)LoadImage(hInst, Filename, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);
	hSrcDC = CreateCompatibleDC(NULL);
	SelectObject(hSrcDC, hbitmap);
	GetObject(hbitmap, sizeof(BITMAP), &bmp);
	nWidth = bmp.bmWidth;
	nHeight = bmp.bmHeight;

	lpdds->GetDC(&hDestDC);

	BOOL isSuccess = BitBlt(hDestDC, xDest, yDest, nWidth, nHeight, hSrcDC, 0, 0, SRCCOPY);

	lpdds->ReleaseDC(hDestDC);
}
void DDApp::Restore()
{
	lpddsPrimary->Restore();
	lpddsBack->Restore();
}



FlashViewer::Init() is called from DDInitialize() Function which is called from the PostInitialize() Function which is run after the WIN32 windows creation and before the message pump. I put comments in to try and help out.

if (FV.Init(this->hWnd, SCREEN_WIDTH, SCREEN_HEIGHT))
		FV.OpenFlash("C:\\FrontEnd.swf");

GeneralRe: AtlAxAttachControl - An outgoing call cannot be made since the application is dispatching an input-synchronous call. Pin
Stuart Dootson21-Apr-09 11:16
professionalStuart Dootson21-Apr-09 11:16 
GeneralRe: AtlAxAttachControl - An outgoing call cannot be made since the application is dispatching an input-synchronous call. Pin
bfoo7522-Apr-09 9:45
bfoo7522-Apr-09 9:45 
AnswerRe: AtlAxAttachControl - An outgoing call cannot be made since the application is dispatching an input-synchronous call. Pin
weir750343-Feb-10 17:30
weir750343-Feb-10 17:30 
QuestionCan CAxWindow's subclass implement in a dll, and create in exe program? Pin
SearchDream30-Mar-09 23:39
SearchDream30-Mar-09 23:39 
AnswerRe: Can CAxWindow's subclass implement in a dll, and create in exe program? Pin
Stuart Dootson31-Mar-09 6:56
professionalStuart Dootson31-Mar-09 6:56 
GeneralRe: Can CAxWindow's subclass implement in a dll, and create in exe program? Pin
SearchDream31-Mar-09 18:25
SearchDream31-Mar-09 18:25 
QuestionIs there anyway to authenticate the COM client? Pin
lucyh3h30-Mar-09 6:05
lucyh3h30-Mar-09 6:05 
AnswerRe: Is there anyway to authenticate the COM client? Pin
Stuart Dootson30-Mar-09 6:57
professionalStuart Dootson30-Mar-09 6:57 
GeneralRe: Is there anyway to authenticate the COM client? Pin
lucyh3h30-Mar-09 10:37
lucyh3h30-Mar-09 10:37 
GeneralRe: Is there anyway to authenticate the COM client? Pin
Stuart Dootson30-Mar-09 11:28
professionalStuart Dootson30-Mar-09 11:28 
GeneralRe: Is there anyway to authenticate the COM client? Pin
lucyh3h31-Mar-09 4:19
lucyh3h31-Mar-09 4:19 
GeneralRe: Is there anyway to authenticate the COM client? Pin
Stuart Dootson31-Mar-09 6:43
professionalStuart Dootson31-Mar-09 6:43 
QuestionIs forward declaration of ATL autogenerated _com_ptr_t possible? Pin
Stone Free26-Mar-09 4:17
Stone Free26-Mar-09 4:17 
AnswerRe: Is forward declaration of ATL autogenerated _com_ptr_t possible? Pin
Stuart Dootson26-Mar-09 4:37
professionalStuart Dootson26-Mar-09 4:37 
GeneralRe: Is forward declaration of ATL autogenerated _com_ptr_t possible? Pin
Stone Free26-Mar-09 5:34
Stone Free26-Mar-09 5:34 
GeneralRe: Is forward declaration of ATL autogenerated _com_ptr_t possible? Pin
Stuart Dootson26-Mar-09 5:49
professionalStuart Dootson26-Mar-09 5:49 
GeneralRe: Is forward declaration of ATL autogenerated _com_ptr_t possible? Pin
Stone Free26-Mar-09 6:57
Stone Free26-Mar-09 6:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.