Как внутри COM компонента узнать, из какой папки он запущен. Мне надо чтобы в папке с моей DLL лежал еще и файл с данными. И при обращении к моему интерфейсу он (интерфейс) смог найти и прочитать этот файл.
Здравствуйте algama, Вы писали:
A>
A>Как внутри COM компонента узнать, из какой папки он запущен. Мне надо чтобы в папке с моей DLL лежал еще и файл с данными. И при обращении к моему интерфейсу он (интерфейс) смог найти и прочитать этот файл.
CString GetModuleFilePath (LPCTSTR szModuleName)
{
TCHAR szPath[MAX_PATH];
HMODULE hModule = ::GetModuleHandle(szModuleName);
ASSERT(hModule != NULL);
::GetModuleFileName(hModule, szPath, MAX_PATH);
return szPath;
}
CString strMyComponentFilePath = GetModuleFilePath ("MyComponent.dll");
GetModuleFilePath — вернёт полный путь к твоей dll,
папку, в которой она лежит, получить теперь совсем не сложно...
Удачи.
Здравствуйте Рек, Вы писали:
Рек>ATL:
Рек> CComModule::m_hInst
Рек>MFC:
Рек> HINSTANCE AfxGetInstanceHandle();
Рек>Win32:
Рек> Прикопать hinstDLL полученый в DllMain;
Всё это справедливо, но не подходит.
Задачка усложняется тем, что я решил посмотреть на VC.NET.
А там все 'запущено'.
// Здесь, судя по всему порыт DLLMain //////////////////
// RecoderSvr.cpp : Implementation of DLL Exports.
#include "stdafx.h"
#include "resource.h"
// The module attribute causes DllMain, DllRegisterServer and DllUnregisterServer to be automatically implemented for you
[ module(dll, uuid = "{24B52C15-2B8E-4FCC-BCF7-225428FDC341}",
name = "RecoderSvr",
helpstring = "RecoderSvr 1.0 Type Library",
resource_name = "IDR_RECODERSVR") ];
// Это заголовочный файл моего компонента /////////////
// TPZRecoderSvr.h : Declaration of the CTPZRecoderSvr
#pragma once
#include "resource.h" // main symbols
#include "atlcomcli.h"
#include <atlcoll.h>
// ITPZRecoderSvr
[
object,
uuid("BAA50D3D-312F-4334-95C0-1E4F6931109F"),
dual, helpstring("ITPZRecoderSvr Interface"),
pointer_default(unique)
]
__interface ITPZRecoderSvr : IDispatch
{
[id(1), helpstring("method RecodeString")] HRESULT RecodeString([in] BSTR InputString, [out,retval] BSTR* OutputString);
};
// _ITPZRecoderSvrEvents
[
dispinterface,
uuid("35508D30-B7CB-4F6F-85FC-D57595236B66"),
helpstring("_ITPZRecoderSvrEvents Interface")
]
// CTPZRecoderSvr
[
coclass,
threading("apartment"),
support_error_info("ITPZRecoderSvr"),
event_source("com"),
vi_progid("RecoderSvr.TPZRecoderSvr"),
progid("RecoderSvr.TPZRecoderSvr.1"),
version(1.0),
uuid("4F63F985-1826-49AC-AE0C-4229E4392E8E"),
helpstring("TPZRecoderSvr Class")
]
class ATL_NO_VTABLE CTPZRecoderSvr : public ITPZRecoderSvr {
public:
CTPZRecoderSvr();
DECLARE_PROTECT_FINAL_CONSTRUCT()
HRESULT FinalConstruct() { return S_OK; }
void FinalRelease() {}
// Methods.
public:
STDMETHOD(RecodeString)(BSTR InputString, BSTR* OutputString);
};
// Это реализация моего компонента ///////////////////
// TPZRecoderSvr.cpp : Implementation of CTPZRecoderSvr
#include "stdafx.h"
#include "TPZRecoderSvr.h"
// CTPZRecoderSvr
CTPZRecoderSvr::CTPZRecoderSvr() {
CString strPath;
HMODULE hModule = ::GetModuleHandle("RecoderSvr.dll");
if(hModule != NULL) {
::GetModuleFileName(hModule, strPath.GetBuffer(MAX_PATH), MAX_PATH);
strPath.ReleaseBuffer();
}
::MessageBox(NULL, strPath, "", MB_OK);
}
STDMETHODIMP CTPZRecoderSvr::RecodeString(BSTR InputString, BSTR* OutputString) {
.
.
.
return S_OK;
}
Да простят меня боги за такой всплеск .......
Как Вам это!
Как говориться RTFM!
Нашел! Всем спасибо!
HINSTANCE hModule = _AtlBaseModule.GetModuleInstance();
Здравствуйте algama, Вы писали:
A>Всё это справедливо, но не подходит.
A>Задачка усложняется тем, что я решил посмотреть на VC.NET.
A>А там все 'запущено'.
A>Да простят меня боги за такой всплеск .......
A>Как Вам это!
Это
Но но как до инстанса докопаться
я не сообразил пока (VC.NET только вчера поставил

)
Узнаешь — напиши!
Жотя назвать это RTFM язык не поворачиваеться.
Слава богу есть исходнеки
Здравствуйте algama, Вы писали:
A>Как говориться RTFM!
A>Нашел! Всем спасибо!
A>A>HINSTANCE hModule = _AtlBaseModule.GetModuleInstance();
A>

Спасибо.