|
use Programming Windows in VC++ by Charles Petzold
|
|
|
|
|
|
I just want to know when we allocate a BSTR using SysAllocString(), where does COM allocate its memory? In process's own heap? some shared memory or where?
BSTR is just a wchar_t with size of string added in its start, if i create my own string in this format and pass it to any COM function, will that work?
+
LPWSTR allocated with CoTaskMemAlloc() doesnot have size in its start, how does COM decide whether to check size from start of string or check for null terminating string??
Muhammad Shoaib Khan
http://geocities.com/lansolution
|
|
|
|
|
1. wild guess - on the heap of the library that exported the SysAllocString ?
2. I think yes, as long as you will be the one who releases the memory back
3. when expects BSTR , it expects the size on the start, when parameter is LPWSTR , it checks for zero termination.
|
|
|
|
|
I believe it's allocated on the COM heap.
M.Shoaib Khan wrote:
LPWSTR allocated with CoTaskMemAlloc() doesnot have size in its start, how does COM decide whether to check size from start of string or check for null terminating string??
When COM allocates a BSTR, it does something like this:
struct _BSTR {
int length;
OLECHAR str[1];
};
BSTR SysAllocString(LPCOLESTR src)
{
int bstr_len = wcslen(src) + 1;
_BSTR* bstr = CoTaskMemAlloc(bstr_len * sizeof(OLECHAR) + sizeof(int));
bstr->length = bstr_len;
wcscpy(bstr->str, src, bstr_len - 1);
return bstr->str;
} As you can see, a BSTR really isn't a LPWSTR. It just appears to be.
--
My name in Katakana is ヨルゲン.
My name in German is Jörgen.
My name in Mandarin/Kanji is 乔尔根 西格瓦德森.
I blog too now[^]
|
|
|
|
|
i wrote a com dll in vc6,and wanna ref it in vc.net,but failed.
another way,i try to import it into my test client app using "#import",then
failed too,with the compiler error:"fatal error C1083: Cannot open type library file:'D:MyFirstSrvDll\Debug\MyFirstSrvDll.dll'"
|
|
|
|
|
|
WMI Blues
I am trying to set the NIC properties on a local machine using WMI. The code to do this is written in C++. I have a windows service and the code to set the NIC settings is handled in that service.
Problem:
I can get two of the properties always (does not matter which one like ip, default gateway or DNS) to set. However, on the third attempt to set any property, the connectServer () function fails (connect server function is required to get the namespace). I tried another experiment, when I restart my service after setting a property it will always work. The CoInitializeSecurity settings are exactly the same as the one in my MFC app. I am clueless at this point and I have a hunch that the code to set NIC settings residing in a service has got something to do with my program not running properly.
Note: I created a test MFC application that uses all my above functions and it works well all the time.
Any help will be appreciated
Thanks
newbee78
|
|
|
|
|
i want to learn COM written in C#, where should i begin
Could you please show me some books that teach me how to program COM with C#
Thank you so much
|
|
|
|
|
C# is not a COM programming language. Do you mean you need to support legacy COM objects in C#? If so, usually the platform will create a wrapper for you without much need to dig into the details of interoperability.
You can interface C# to COM objects, you can call the COM libraries from C# by declaring the appropriate dll imports, you can create NET assemblies that are compatible with COM objects, but C# is not intended to program COM directly.
If you want to actually create COM objects you really should be working in C++. "Beginning ATL 3 COM" by Richard Grimes et al. is a good place to start, if you can find a copy. It was published by Wrox Press who is no longer in business. Some titles have been republished by APress, this is not one of them, but you can probably still find copies of the Wrox version online.
|
|
|
|
|
Actually you can write COM in C#. It is a horrible implementation technology for COM. I have done this using a C# server and a C++ client.
In C# you declare an interface like this:
[Guid( "ert565645-EA16-4a8c-8CDD-434564565675" ),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface _<MyObjectName>
{
string InterfaceMethod1;
InterfaceMethod2
}
Your class then extends that interface:
[Guid( "3D655F63-118B-4e28-B1D5-30DD4AE77424" )]
public class <MyObjectName> : _<MyObjectName>
{
public string Method1()
{
return "Silly";
}
string InterfaceMethod1()
{
return Method1();
}
Stuff like that can work. It is difficult to work with and best advised to stay away from. When you return an object from a call in an interface you will run into problems that the interface does not know about the object and therefore making calls on that object becomes problematic. To deal with this problem you will have to add an attribute to the declaration of your Class. This Attribute [System.Runtime.InteropServices.ComVisible(true)] is added to the declaration of your class.
Please note that doing this flys in the face of everything that COM interactions stand for, but it does work. Also you will have to generate a hack header file to handle certain types used when the typelibrary is imported into your C++ code.
Regards
Ward
Frag
Try, Fail..Fail, Succeed
Tool Developer
Michigan, USA
|
|
|
|
|
Is it possible to save a Word Document to a stream using automation?
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
Yes you can save word file as stream through automaion
Further elaborate ur problem !
Cheers,
Vishal
|
|
|
|
|
He he he, you wouldn't work in management would you?
Another team on my project, has created code that inserts user data into fields in a word document.
I'm creating a web front end, that has to let the user view the document. I don't want the mess with temporary files, and I actually don't have the direct file access to the destination path.
So, instead of serializing the document to a file, I want to serialize it to a stream like IStream ( ).
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
|
Thanks!, it looks good...
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
Bugger, didn't do it for me.
The problem is: I have a pointer to a CoClass Document in memory, I don't want to save it to disk, which seems to be the only option in the _Document interface.
_Document does not inherit the IStorage or IStream interface, so to use structure storage, I would have to first store the Document on the harddisk, and then open it using eg. StgOpenStorage.
The idea was to stream the document to a web client without touching the harddisk.
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
I am unsure if you can store it as a stream. IIRC, word document files are storages, and not streams. I suppose you could save the OLE Structured Storage as a stream, but that's like storing a file system within a file - it probably doesn't do you any good.
--
My name in Katakana is ヨルゲン.
My name in German is Jörgen.
My name in Mandarin/Kanji is 乔尔根 西格瓦德森.
I blog too now[^]
|
|
|
|
|
Thanks, I was beginning to wonder if I was going blind, and just couldn't see the method name. The best thing I've come up with, is Get_XML().
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
hello
I found this
http://www.codeproject.com/com/DHTML_Interfaces.asp
here on cp but it only works for ie
is there any way in wich I could apply this for mozilla or does mozilla simply not use coms like ie does and if not how else could I achieve the same results
|
|
|
|
|
Help!
A series of business objects have been created in C# and COM Interop has been enabled to send objects back and forth between the Managed C# and the unmanaged C++ code.
After hurdling a series of obstacles to get these two worlds talking with each other, the problem of accessing the objects returned in a SAFEARRAY from the C# side is causing a problem.
Here is a code sample from the C# side.
The interface is _YohoFolders while the CoClass is YohoFolder.
ArrayListRule RuleFolders;
public object[] GetFolderArray()
{
return RuleFolders.ToArray();
}
object[] _YohoFolders.GetFolderArrayI()
{
return GetFolderArray();
}
However on the other side of the gap between Managed and Unmanaged the only elements that are accessible are the interfaces. Is there a methodology for passing back an Array of interfaces back to the C++ side of the fence? If so please let me know.
In the C++ world the code looks something like this:
MyNamespace::YohoSingleFolder pFolder;
pLeSafe = pAllFolders->GetFolderArrayI();
for( int i = 0; i < nTotalFolders; i++ )
pFolder = (MyNamespace::YohoSingleFolder)(pLeSafe[i].pvData);
End code
If anybody has any ideas, please let me know.
Thank you all in advance for looking at this.
Regards
Ward
Frag
Try, Fail..Fail, Succeed
Tool Developer
Michigan, USA
|
|
|
|
|
I found the solution to this. Actually by configuring things properly a person can directly access the object inside of the Unmanaged code. I am not sure this is a desired ability, but it can be done. It may be something that you would like to do, if so let me know and I will post the code.
Ward
Frag
Try, Fail..Fail, Succeed
Tool Developer
Michigan, USA
|
|
|
|
|
hi
i am new to COM and want to know the difference b/w COM component and ActiveX control.
thanks in anticipations
Muhammad Azam
|
|
|
|
|
|
Thanks a lot, i got it but one thing is still ambiguous........then why do we need ActiveX controls when we have COM ?
thanks in anticipation
Azam
|
|
|
|