Click here to Skip to main content
15,890,579 members
Home / Discussions / COM
   

COM

 
GeneralRe: Help...floundering...BSTR? Pin
Member 9624-May-02 10:17
Member 9624-May-02 10:17 
GeneralRe: Help...floundering...BSTR? Pin
Jason Henderson24-May-02 18:51
Jason Henderson24-May-02 18:51 
AnswerRe: Help...floundering...BSTR? Pin
Mazdak25-May-02 20:59
Mazdak25-May-02 20:59 
Generalhelp bluetooth. Pin
23-May-02 9:14
suss23-May-02 9:14 
GeneralRe: help bluetooth. Pin
soptest23-May-02 9:14
soptest23-May-02 9:14 
GeneralRe: help bluetooth. Pin
David Wulff23-May-02 16:26
David Wulff23-May-02 16:26 
GeneralRe: help bluetooth. Pin
Henrik Husted23-May-02 17:26
Henrik Husted23-May-02 17:26 
GeneralDCOM server crash!!! Pin
Jason Henderson23-May-02 6:48
Jason Henderson23-May-02 6:48 
I have a DCOM server running and it creates a Tray icon. The tray icon can be right clicked and a menu pops up. One of the menu items is to Close the program.

On WinNT machines, when you try to close the program this way or by sending WM_CLOSE to it, it gives me an Access Violation in Ole32.dll @ 0x77b45677. Its happening in the RevokeClassObjects function but that's all I can decipher.

Has anyone else had any similar experience? I can't find anything like this on the net. Please help! Frown | :( Frown | :(

Here is some code:
// i deleted some standard stuff

//Monitors the shutdown event
void CExeModule::MonitorShutdown()
{
    while (1)
    {
        WaitForSingleObject(hEventShutdown, INFINITE);
        DWORD dwWait=0;
        do
        {
            bActivity = false;
 			dwWait = WaitForSingleObject(hEventShutdown, dwTimeOut);
        } while (dwWait == WAIT_OBJECT_0);

        // timed out
        if (!bActivity && m_nLockCnt == 0 && bOKToShutDown) // if no activity let's really bail
        {
#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
            CoSuspendClassObjects();
            if (!bActivity && m_nLockCnt == 0)
#endif
                break;
        }
    }
    CloseHandle(hEventShutdown);
    PostThreadMessage(dwThreadID, WM_QUIT, 0, 0);
}

// deleted more standard stuff

/////////////////////////////////////////////////////////////////////////////
//

LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case UM_NOTIFY_ICON:
		switch(lParam) 
		{
		case WM_LBUTTONDBLCLK:
			::SendMessage(hwnd, WM_COMMAND, IDM_ABOUT, 0); 
			break;
		case WM_RBUTTONUP:
			{
				POINT point;
				HMENU hMenu, hSubMenu;

				// Get mouse position
				GetCursorPos(&point);

				// Popup context menu
				hMenu = LoadMenu(hInstCopy, MAKEINTRESOURCE(IDR_ESINETCONNECT_MENU));
				hSubMenu = GetSubMenu(hMenu, 0);
				SetMenuDefaultItem(hSubMenu, IDCLOSE, FALSE);
				SetForegroundWindow(hwnd);         // Per KB Article Q135788

				TrackPopupMenu(hSubMenu, TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_LEFTALIGN, 
					point.x, point.y, 0, hwnd, NULL);

				PostMessage(hwnd, WM_NULL, 0, 0);   // Per KB Article Q135788
				DestroyMenu(hMenu);
			}
			break;
		default:
			return FALSE;
		}

		break;
	case WM_COMMAND:
		switch (wParam)
		{
		case IDCLOSE:
			PostMessage(hwnd, WM_CLOSE, 0, 0);
			break;
		case IDM_ABOUT:
			::MessageBox(hwnd, szMessage, szTitle, MB_OK); 
			break;
		default:
			break;
		}
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hwnd, message, wParam, lParam);
	}

	return 0;
}

extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, 
    HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/)
{
	HWND hwnd = NULL;
	WNDCLASSEX wc;
	NOTIFYICONDATA nid;
	HKEY phkResult = NULL;

	// check if this is already running
	hwnd = FindWindow("name withheld", szTitle);
	if (hwnd != NULL) return 0;

	// windows class stuff deleted

	hwnd = CreateWindow("name withheld", szTitle, WS_OVERLAPPEDWINDOW, 
		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, HWND_DESKTOP, NULL, 
		hInstance, NULL);

	if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Key\\Key",
			 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &phkResult, NULL) == ERROR_SUCCESS)
	{
		RegSetValueEx(phkResult, "HandleToHwnd", NULL, REG_DWORD, (LPBYTE)&hwnd, sizeof(DWORD));

		RegCloseKey(phkResult);
	}

	hInstCopy = hInstance;

	nid.cbSize = sizeof(NOTIFYICONDATA);
	nid.uID = ID_TRAYICON;
	nid.hWnd = hwnd;
	nid.hIcon = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);
	nid.uCallbackMessage = UM_NOTIFY_ICON;
	nid.uFlags = NIF_ICON | NIF_TIP| NIF_MESSAGE;
	strcpy(nid.szTip, szTitle);

	Shell_NotifyIcon(NIM_ADD, &nid);

	_Module.bOKToShutDown = FALSE;

    lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT

#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
    HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
#else
    HRESULT hRes = CoInitialize(NULL);
#endif
	
	CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_NONE, RPC_C_IMP_LEVEL_IMPERSONATE, 
		NULL, EOAC_NONE, NULL);

    _ASSERTE(SUCCEEDED(hRes));
    _Module.Init(ObjectMap, hInstance, &LIBID_ESINETCONNECTLib);
    _Module.dwThreadID = GetCurrentThreadId();
    TCHAR szTokens[] = _T("-/");

    int nRet = 0;
    BOOL bRun = TRUE;
    LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
    while (lpszToken != NULL)
    {
        if (lstrcmpi(lpszToken, _T("UnregServer"))==0)
        {
            _Module.UpdateRegistryFromResource(IDR_Esinetconnect, FALSE);
            nRet = _Module.UnregisterServer(TRUE);
            bRun = FALSE;
            break;
        }
        if (lstrcmpi(lpszToken, _T("RegServer"))==0)
        {
            _Module.UpdateRegistryFromResource(IDR_Esinetconnect, TRUE);
            nRet = _Module.RegisterServer(TRUE);
            bRun = FALSE;
            break;
        }
        lpszToken = FindOneOf(lpszToken, szTokens);
    }

    if (bRun)
    {
		// hide the main window
		ShowWindow(hwnd, SW_HIDE);
		UpdateWindow(hwnd);

        _Module.StartMonitor();
#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
        hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, 
            REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED);
        _ASSERTE(SUCCEEDED(hRes));
        hRes = CoResumeClassObjects();
#else
        hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, 
            REGCLS_MULTIPLEUSE);
#endif
        _ASSERTE(SUCCEEDED(hRes));

		//RPC_STATUS rpc_status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, 1);

        MSG msg;
        while (GetMessage(&msg, 0, 0, 0))
		{
			TranslateMessage(&msg);
			
			if (msg.message == WM_CLOSE) 
				_Module.bOKToShutDown = TRUE;
            
			DispatchMessage(&msg);
		}

		_Module.RevokeClassObjects();
    	Sleep(dwPause); //wait for any threads to finish
    }

	Shell_NotifyIcon(NIM_DELETE, &nid);

	RegDeleteKey(HKEY_CURRENT_USER, "Software\\Key\\Key");

    _Module.Term();
    CoUninitialize();
    return nRet;
}


Like it or not, I'm right.
GeneralRe: DCOM server crash!!! Pin
soptest23-May-02 7:34
soptest23-May-02 7:34 
GeneralRe: DCOM server crash!!! Pin
Jason Henderson23-May-02 16:18
Jason Henderson23-May-02 16:18 
GeneralRe: DCOM server crash!!! Pin
Jason Henderson24-May-02 18:47
Jason Henderson24-May-02 18:47 
GeneralRe: DCOM server crash!!! Pin
Vi224-May-02 3:30
Vi224-May-02 3:30 
GeneralSign Files! Pin
erasmo23-May-02 6:01
erasmo23-May-02 6:01 
GeneralRe: Sign Files! Pin
Matt Philmon24-May-02 12:18
Matt Philmon24-May-02 12:18 
GeneralRe: Sign Files! Pin
erasmo27-May-02 7:28
erasmo27-May-02 7:28 
GeneralVC6 IDE (Cannot create method) Pin
ssirisha22-May-02 1:53
ssirisha22-May-02 1:53 
GeneralRe: VC6 IDE (Cannot create method) Pin
Rama Krishna Vavilala22-May-02 2:01
Rama Krishna Vavilala22-May-02 2:01 
GeneralRe: VC6 IDE (Cannot create method) Pin
ssirisha22-May-02 2:13
ssirisha22-May-02 2:13 
GeneralRe: VC6 IDE (Cannot create method) Pin
Francisco Moraes22-May-02 2:22
Francisco Moraes22-May-02 2:22 
GeneralRe: VC6 IDE (Cannot create method) Pin
Rama Krishna Vavilala22-May-02 3:16
Rama Krishna Vavilala22-May-02 3:16 
GeneralRe: VC6 IDE (Cannot create method) FIXED Pin
ssirisha22-May-02 3:19
ssirisha22-May-02 3:19 
GeneralAdding a Combobox to toolbar (ATL) Pin
21-May-02 22:38
suss21-May-02 22:38 
GeneralVBScript and COM Pin
Vivek Rajan21-May-02 6:08
Vivek Rajan21-May-02 6:08 
GeneralRe: VBScript and COM Pin
soptest21-May-02 7:24
soptest21-May-02 7:24 
GeneralRe: VBScript and COM Pin
Vivek Rajan21-May-02 9:16
Vivek Rajan21-May-02 9:16 

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.