|
Hmm, never came back to this, there were so many things running on this particular box, it was resource related.
|
|
|
|
|
Hi All,
I've been planning for some time to do a project with COM for the community of software developers.
The project, in essense, is to generalize access to all information on the PC in a simple way, something like what WMI does, only better (read simpler).
I wonder, however, if i'm not too behind doing this (a few years), and whether a COM project, if it is good, can still be applaused by .NET developers?
Any opinions here are welcome!
Cheers!
|
|
|
|
|
I know this is a bit early to wonder if this post would ever be answered, but i published information about the idea here: http://www.codeproject.com/script/Forums/View.aspx?fid=1641[^]
It's titled Researching Opinions: Professional System Library
I think this might be of interest to all COM developers.
Cheers!
|
|
|
|
|
you know i have heard similar things about people flaming com
you know what it works its easy and it gets the job done so it is fine ill applaud anything created
that is the whole point of the framework so we can build on top of stuff made and the object oriented paradigm
we dont need to know certain things except what needs to be exposed to our classes and functions inheritance polymorphism
etc
so com makes it easy by dragging a control and building off of it
use anything that works bro
|
|
|
|
|
Thank you for the encouragement, I appreciate it very much. I also came to the conclusion that there's no way to evaluate any idea until you show results, so I started on this project two weeks ago. I got a website for it: www.prosyslib.com, net, org. So, I’m seriously planning to be back here with some first results soon, something a lot more tangible than the theory (even changed my signature )
Cheer'o!
Professional System Library on www.prosyslib.com, simplifying life for software developers.
|
|
|
|
|
Hello Friends,
I have an <b>ATL project in Visual Studio 2005, but now I want it in Visual C++6.0.</b>
I have used one utility available on Code Project only i.e.
<b>prjconverter.exe</b>
it converted .sln to .dsw BUT on building the project,
I am having many error, mainly
<b>"C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlcom.h(2945) : error C2065: '_Module' : undeclared identifier"</b>
Because even in converted project,
class Coeapi_sampleModule : public <b>CAtlDllModuleT</b>< Coeapi_sampleModule >
{
public :
DECLARE_LIBID(LIBID_oeapi_sampleLib)
DECLARE_REGISTRY_APPID_RESOURCEID(IDR_OEAPI_SAMPLE, "{2FB8F87B-D079-497D-8948-F2F060162392}")
};
<b>Coeapi_sampleModule _AtlModule</b>;
<b>BUT</b>
what I want (generated by compiler if we build in vc 6) is
<b>CComModule _Module;</b>
and i read that CComModule is obsolete now, but I have to use it anyway because <b>I have to code & build the project in Visual C++ 6.0</b> only not in Visual Studio 2005.
Please Help.
Thanks well in Advance!
dolly,
N,IN
|
|
|
|
|
Hi,
I am in need of a MTA (Multithreaded) COM component for one of my application.
I would like to know if VC# can be used to develop the MTA COM component instead of VC++? If possible, how? or any info regarding it will be helpful.
Thanks in advance.
|
|
|
|
|
Hi,
When you program COM components in C++ you genereally use ATL, wich helps you a lot to deal with the COM gore details.
Since C# is a managed Language that runs over the .NET framework it was not designed to support COM developing which is an older unmanaged technology
If you want to use COM components from you C# App I strongly recommend you to program them in C++ and loading them into your C# project.
But you should first evaluate if its strongly necessary to use COM instead of a .NET component programmed in C#
JO
|
|
|
|
|
I want to make a function in COM dll which receive one character string and returns one character string. Since scripting languages dont use char* please suggest how to make this function in COM and how to use it. Please give any sample.
Manoj Kumar Chauhan
|
|
|
|
|
[id(...)] HRESULT SomeMethod([in] BSTR inString, [out,retval] BSTR * outString); In script this method can be used as
string2 = obj.SomeMethod(string1)
string2 = obj.SomeMethod("text1")
With best wishes,
Vita
|
|
|
|
|
Thanks it's working
Now if i use CHAR* instear of BSTR* then will it work for scripting language?
Please give some samples where to use BSTR* and CHAR* for scripting & non scripting language. If function inside COM dll takes CHAR* then i should pass BSTR if i'm using dll in scripting language
please give some samples for this
Manoj Kumar Chauhan
|
|
|
|
|
Now if i use CHAR* instead of BSTR* then will it work for scripting language?
No. At the most, [in] parameter might be considered as WCHAR*.
Please give some samples where to use BSTR* and CHAR* for scripting & non scripting language. If function inside COM dll takes CHAR* then i should pass BSTR if i'm using dll in scripting language
COM object doesn't use "CHAR*" in specification of functions, but can convert "CHAR*" to "BSTR" and viceversa.
With best wishes,
Vita
|
|
|
|
|
Thanks for explanation
So you mean it's always preferable to use BSTR for COM not any char*
And if i make any function in COM which takes char* as input then i need to pass char* when i call this function. Is it right?
Because ATL gives the option to make char* for any function argument so i can give it. My question is how i'll handle this char* in scripting language
Manoj Kumar Chauhan
|
|
|
|
|
When I spoke "COM object doesn't use "CHAR*" in specification of functions", I meant that for string parameter, not for CHAR parameter, which is valid in COM. So you can write
f(..., [in] CHAR* c, ...)
f(..., [in,out] CHAR* c, ...)
f(..., [out] CHAR* c, ...)
f(..., [out,retval] CHAR* c) but you will be able to pass only one symbol (or one byte), not the whole string.
With best wishes,
Vita
|
|
|
|
|
Thanks for your explanation
Is it possible if we pass any iostream object to COM function and COM function write some text in the file attached to iostream object and return.
Manoj Kumar Chauhan
|
|
|
|
|
"iostream" object is C++ object, not accessible directly from scripts and non-C++ clients and unallowed in COM accordingly.
With best wishes,
Vita
|
|
|
|
|
Thanks. There is one more doubt please clear this also.
If i want to return any variable length string from COM then i can allocate memory in COM and return it to exe (return BSTR*). Finall exe which's using the COM will free the memory. Is this OK? How to make same parameter as input/output in COM function?
How to return more than one string through COM function. suppose if i have function
int func(BSTR inputstring, BSTR* outstring1, BSTR* outstring 2);
Here i want to return 2 strings from this function.
COM dont give the option to pass output argument when we call the function
Manoj Kumar Chauhan
|
|
|
|
|
I implement one function in COM which allocate some memory to array and return this.
int AllocateData(int length, BSTR* OutArray)
{
// there is some data in a ansi array, i return this data from this COM function
wchar_t* wstr = (wchar_t*)calloc(sizeof(WCHAR),length+1);
MultiByteToWideChar(CP_ACP, 0, ansiarray, length, wstr, length) ; free(ansiarray);
*OutArray = (BSTR)wstr;
}
When i use this dll i call this function like
BSTR st;
st = cominterface->AllocateData(500);
When this function is called i get some error for memory leak. Please suggest how to fix it.
Manoj Kumar Chauhan
|
|
|
|
|
MKUser wrote: COM dont give the option to pass output argument when we call the function
That's not true (see the [OUT] IDL attribute).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks. As per your comments i have solved the error when use [out] in idl file. But if i use [out,retval] then i get error.
I create a sample. Please check the below code.
main()
{
BSTR ab;
ab = allocmem();//i get run time memory error when return from this function
}
_bstr_t allocmem()
{
BSTR x;
allocmem2(&x);
return _bstr_t(x, false);
}
void allocmem2(BSTR *x)
{
char ansi[27];
memset(ansi,0,27);
for(int i = 0; i < 26; i++)
ansi[i] = 48 + i + 1;
wchar_t* wstr = (wchar_t*)calloc(sizeof(WCHAR),26);
MultiByteToWideChar(CP_ACP, 0, ansi, 26, wstr, 26) ;
*x = (BSTR)wstr;
}
Please suggest how to solve this error.
Manoj Kumar Chauhan
|
|
|
|
|
BSTR are strange beasts, you need to use SysAllocString [^](or similar) to allocate a new BSTR object.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Ok Let me explain my problem in detail.
In COM i create one function which takes one input and another output argument
idl file contains
HRESULT functionname([in] int length,[out,retval] BSTR* OutArray)
In function definition in COM class
HRESULT functionname(int length,BSTR* OutArray)
{
WSTR warray;
suppose warray contains some string and i want to return that string so i'll write
*OutArray = (BSTR) warray;
or if i try with following code then i think it's not correct
*OutArray = SysAllocString(wstr);
}
i use this dll and call it like
BSTR str;
str = cominterface->functionname(pass input length here);
When i build exe it generate tlh and tli files.
The tli file contains following code for that function
inline _bstr_t IExportComDll::functionname( int length ) {
BSTR _result = 0;
HRESULT _hr = raw_functionname(length, &result);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _bstr_t(_result, false);
}
Now please tell me where i can change the code. Where to use SysAllocString. I cant change the code inside tli file. This function returns a string. So ATL write its wrapper code in tli file. When i call this function in some exe,After returning from wrapper code of tli file i get memory error because it try to free BSTR string.
Manoj Kumar Chauhan
|
|
|
|
|
Why do you need to pass the length?
For instance the following should work fine:
HRESULT functionname(BSTR * OutArray)
{
*OutArray = SysAllocString( L"Foo");
}
in the client application you may do
BSTR str;
str = cominterface->functionname();
You should also remember to call SysFreeString(str); there.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I'm doing following
HRESULT functionname(BSTR * OutArray)
{
// suppose there is some ansi array which contains some data
// length is int type which keeps size of this ansi array
wchar_t* wstr = (wchar_t*)calloc(sizeof(WCHAR),length+1);
MultiByteToWideChar(CP_ACP, 0, ansiarray, length, wstr, length) ;
free(ansiarray);
ansiarray= NULL;
*OutArray = SysAllocString( wstr);//(BSTR)wstr;
memset(wstr,65,sizeof(WCHAR) * length+1);
free(wstr);
wstr = NULL;
}
When i use this dll
BSTR st;
st = functionname();
After this statement st contains some garbage data.
While when i debug the code in tli file, it returns valid data
inline _bstr_t IExportComDll::functionname( )
{
BSTR _result = 0;
HRESULT _hr = raw_functionname(&_result);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _bstr_t(_result, false);
//here _result contains valid data which is returned by COM function
//HRESULT functionname(BSTR * OutArray)
}
Now please tell me where i'm wrong. Please correct my mistake
Manoj Kumar Chauhan
|
|
|
|
|
MKUser wrote: inline _bstr_t IExportComDll::functionname( )
The above function returns a _bstr_t instance. Possibly it cannot assigned as it stands to as BSTR variable, hence you need either to
define st as _bstr_t , for instance
_bstr_t st;
st = YourCOMInterface->functionname();
or
use the Detach method of _bstr_t (see [^]), for instance
BSTR st;
st = (YourCOMInterface->functionname()).Detach();
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|