|
Firstly, if you're using .NET 2.0 or later you should be using the SerialPort class. The MsComm control is ancient and wasn't particularly good even with Visual Basic 6.0.
Secondly, serial communications are not framed - write boundaries are not preserved. You will get whatever is in the buffer when the read timeout expires, depending on how you've set up your serial port timeouts; this may be less than the number of bytes you requested.
"Multithreading is just one damn thing after, before, or simultaneous with another." - Andrei Alexandrescu
|
|
|
|
|
|
You must always match AddRef and Release calls. Do not rely on the return value of Release.
QueryInterface and CoCreateInstance add a reference implicitly, so they must always be matched with a call to Release.
"Multithreading is just one damn thing after, before, or simultaneous with another." - Andrei Alexandrescu
|
|
|
|
|
In VS6 C++, I have a windowless ATL control. To get a Device Context from the container, I belive I need to execute the GetDC() method of one of the base classes for the control, specifically IOleInPlaceObjectWindowless. I tried to do this:
CDC *pDC = IOleInPlaceObjectWindowless::GetDC();
But it doesn't work so I am at a loss as to how to execute a method on the IOleInPlaceObjectWindowless interface.
Any help would be greatly appreciated,
Thanks,
Doug
Doug Knudson
|
|
|
|
|
You can use methods exposed by interfaces ,only. Or you want to say smething else ?
|
|
|
|
|
Thanks for the reply. I didn't ask my question very well, but basically I am writing a windowless ATL component and need the Device Context from the Parent/Container so that I may draw in event handlers (for example, in MouseMove()). During my length time searching, all I could find was people saying that I needed to just execute the GetDC() method of the IOleInPlaceObjectWindowless interface like this:
HDC hDC = NULL;
HRESULT hr = IOleInPlaceObjectWindowless::GetDC(myRect,myFlags,&hDC);
The compiler interprets the above as trying to execute a static member function, which, of course, GetDC() isn't. If I just use:
GetDC();
I get the API GetDC() that expects there to be a m_hWnd, which there isn't (windowless control), so I am pretty lost as to how to do this.
Thanks,
Doug
Doug Knudson
|
|
|
|
|
There is no GetDC method on the IOleInPlaceObjectWindowless interface, nor any of its base interfaces.
You should generally be doing all your drawing in your implementation of IViewObject::Draw , i.e. in OnDraw .
If you need to do some drawing outside of this, the GetDC call is on IOleInPlaceSiteWindowless, which you have to ask the container for. I believe you should call InternalGetSite (which is inherited from CComControlBase ) to retrieve a pointer to this interface.
"Multithreading is just one damn thing after, before, or simultaneous with another." - Andrei Alexandrescu
|
|
|
|
|
Hi Mike,
Thanks! I will give that a try. I am doing the bulk of my drawing in OnDraw() but I need to drag a selection rectangle during the MouseDown, MouseMove, MouseUp events so I need to (or at least I think I need to ) have the DC outside of what is handed to me in OnDraw() ??
Thanks again,
Doug
Doug Knudson
|
|
|
|
|
I am trying to access a .net dll from excel via VBA. I am able to successfully do that on my machine.
But when I try to do the same on user's machine(which does not have VS 2003 but has .net Framework 1.1) The excel (as soon as I open the excel file) gives me an error "File or assembly name QueryData, or one of its dependencies, was not found".
I follow the following steps on the user's machine:
1. Register the .net dll using regasm tool and create a .tlb file
Regasm QueryData.dll /tlb:QueryData.tlb
2. Add this tlb file to the references of the excel.
3. Close the excel sheet and open it again (I have some code in the workbook_open event of excel).
I don't get any errors while generating the tlb file, but as soon as I open the excel I get the error mentioned above. I have also copied all the dlls from the bin folder of my dev machine to the folder (having QueryData.dll) on the user machine.
I have no clue why the excel file is not able to find the dll. Any pointers??
Thanks,
Neeraj
|
|
|
|
|
How to convert interface object to its class?
I have an interface object say IMarkSet. I passed to an COM function. There i need to access a function which takes CMarkedSet .
Thanks
Mohan
|
|
|
|
|
AnanyaMohan wrote: I have an interface object say IMarkSet. I passed to an COM function. There i need to access a function which takes CMarkedSet .
^
|
v
How to convert interface object to its class?
The answer is really simple: you don't.
The reason may be a bit more complicated....
This is a design flaw either in your class or the interfaces it exposes and perhaps even a combination. This is all about abstraction and encapsulation.
A COM object/server exposes several interfaces that can be used to alter the behaviour and/or state of the server. Whatever the server is supposed to do, it must be possible to trigger it through the interfaces. Perhaps you need to query for another interface, or even implement an additional interface, but that's all right; it's supposed to work that way.
But how the server accomplishes its task is entirely up to the server and is encapsulated behind interfaces.
In short: you have to re-evaluate your design.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
AnanyaMohan wrote: There i need to access a function which takes CMarkedSet
That simply is wrong thing, you are trying to do. Always talk through interface.
|
|
|
|
|
Hi,
Iam using a c++ dll in my .net application.It is running fine on the system where visual studio 2005 is installled.
In the deployment environment we have only framework2.0 installed on the machine.Then Iam getting a pop-up error as
"<big><b>Microsoft visual c++ runtime library
Runtime error
c:\testapp\bin\debug\test.exe
The application has requested the application to terminate in the unusual way
Please contact the application's support team for more information</b></big>"
Please kindly help ASAP
|
|
|
|
|
One thing you can look at to troubleshoot this issue...use depends.exe to see what dependencies you have in your dll. If you suspect it might be the framework, perhaps look at the runtime libraries like MSVCR80.dll to see what versions are on your dev system vs your deployment system.
Also, you didn't really provide much information, so I'm not sure if anyone can really provide much feedback.
|
|
|
|
|
My application working fine in the dev environment.But in the testing /production environment
it is not working because that environment has only
windows server 2003
IIS
.net2.0 framework
In my application I have Used some microsoft VC++ dll's also along with .net dll's.
Now Iam getting "RUNTime Error" pop-up screen message as below
" The Application has been terminated in an Unusual Way"
On googling i came to know that some dll's like msvcrt.dll of windows server 2003 has to be changed...But Iam not pretty sure about it..
In Production/test environment there is only framework installed ,but there is no visual studio installed on it.may be due that this error may occur...
So kindly post your suggestions and views to help me
I tried the following as suggested by you:
1. I have installled the redistributable package suggested by you.
after installing i restarted the PC even now also I got the same runtime pop-up error.
2. Then I checked even with the dependency walker for the dll.
I found that there is no miising dll.
3. Then I tried by installing Visual C++ express edition..even then also i got the same pop-up error.
Kindly help me.....
|
|
|
|
|
Hello there,
I've made ActiveX control which is used in my webpage to get client's system information.
I followed the article http://www.codeproject.com/KB/COM/CompleteActiveX.aspx[^] to create and sign the control.
In short I followed this steps:
1. the control is created and is marked as safe
2. The control is packaged into the cab file
3. The cab file is signed by class3 digital certificate issued by Thawte
4. The control is now embedded into the web-page.
The command used for creating cab file and signing it are
c:\cabsdk\bin\cabarc -s 6144 N SystemCheck.cab SystemCheck.ocx SystemCheck.inf
signcode -n "SystemCheck" -i http:
Now when I run the control it runs from most of the machines but from some machines it gives "Unknown publisher" Error.
The page is hosted online and is available at http://92.61.60.4/vod/SystemCheck1.htm[^]
Please note that it doesn't give unknown publisher error on all machines.
Thanks in advance...
|
|
|
|
|
Well, I have a question about the usuage of CComPtr, but I think I know the answer, but would like to make sure I understand this completely...
CComPtr is a smart pointer class for managing COM interface pointers, thus I don't need to worry about calling AddRef for Release methods, since they are automatically called. From what I've read, the Release method will be called when the CComPtr goes out of scope.
I'm have the task of maintaining a COM client app (first time with COM) and I was thinking about 'reusing' a particular instance of a CComPtr (no need to declare a new one, since there's one already!) The only thing that had me worried what that by reusing the CComPtr does that screw up the reference counting and create a memory leak... psuedocode below:
{
CComPtr<isomething> myIsomething = (some Isomething interface)
...do stuff to the CComPtr...
...lets reuse it...
myIsomething = (some other Isomething interface)
}
Since the myIsomething didn't go out of scope when I set "myIsomething" to another interface, I was worried that it may be an issue. So after a day of digging around this is my conclusion:
This is actually OK, since if we look at the definition of this template, the = operator is overloaded as such:
T* operator=(T* lp) {
return (T*)AtlComPtrAssign((IUnknown**)&p, lp);
}
When I looked up AtlComPtrAssign, it seems that it will call release on the interface pointer, prior to reassignment to the new interface. If that's true, there shouldn't be any issues with reference counting and I can continue on my merry way?
|
|
|
|
|
Hello alchong,
>>...lets reuse it...
>>myIsomething = (some other Isomething interface)
Yes, this is OK AFAIK. One reusage problem that I have encountered before is related to QueryInterface().
If you were to do this :
ISomething -> QueryInterface(IID_ISomething, (void**)&myIsomething);
you will get an assertion failure if myIsomething is already holding onto another interface pointer.
You can overcome reusage problems by first assigning myIsomething to NULL as in :
myIsomething = NULL;
before reusing it.
- Bio.
|
|
|
|
|
I see, by assigning it to NULL, that forces the release on the currently held interface, correct? Thanks for the extra tip!
|
|
|
|
|
Hello, i'm created installation project and during installing process i need to config Component Services -> Computers- >My Computer->Dcom Config security properties.
In particular...Security - >Launch Permission : Add ASPNET user and give him rights to Activation/Launch.
I'm know how to do this manually, but how do this on programly on C#?
Thank's and sorry for my english.)))
|
|
|
|
|
I have a VC++ generated COM executable that I wish to launch under a different user to the launching process, i.e. the interactive user.
I have found that this can normally be set in DCOMCNFG, under the identity tab of the properties for the particular application.
All other programs listed in DCOMCNFG have an application type of ‘local server’ and display the ‘Identity’ tab but my program has an ‘application type’ of ‘Remote server’ and the properties of my program do not include this tab.
I have tried adding the 'RunAs' registry entry manually to no effect.
Can anyone tell me why my program is listed as a ‘remote server’ rather than a ‘local server', or what else I should be doing.
Inside the program uses the wizard generated code:
_AtlModule.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE)
_AtlModule.RegisterServer(TRUE)
Thanks
Steve.
|
|
|
|
|
For anyone who might be interested I found the problem...
When the server was registered the AppId field of the CLSID was not set.
As a permanent solution I changed the .rgs file that sets this value from using a parameter to using the explicit value.
NoRemove CLSID
{
ForceRemove....
{
ProgID
.
val AppID = s '%APPID%'
val AppID = s {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
}
}
|
|
|
|
|
Hello!
I am working on a C# COM-Server and a C++ COM client app. The client in fact
loads a dll-plugin containing the COM client in a class that acts as a com
event reciever:
extern "C"
__declspec(dllexport)
int ndofInit();
extern "C"
__declspec(dllexport)
void* ndofOpen(void* wnd);
extern "C"
__declspec(dllexport)
void ndofShutdown(void* deviceHandle);
[ event_receiver(com) ]
[ module(type=dll, name="NDOF") ]
class NDOFServer
{
public:
NDOFServer() {}
virtual ~NDOFServer();
...
}
Everytime I start the client I get the following error:
Debug Assertion failed!
Program ...
File: C:\Programme\Microsoft Visual Studio 8\VC\atlmfc\include\atlbase.h
Line 2706
Expression _pAtlModule == 0
Clicking Retry and returning to my code reveals that this error occurs when
the constructor of NDOFServer() is called.
The constructor is called this way by the client app:
extern "C"
__declspec(dllexport)
int ndofInit()
{
if (sNdofServer == NULL)
sNdofServer = new NDOFServer();
return 1;
}
This error seems not to occur when the client plugin-DLL is used with
another COM server offering the same classes etc. written in C++ (whose code
I do not know).
I tried to switch some more or less relevant options in the project
properties like:
- MFC usage static/shared/Windows shared
- ATL usage static/shared/none
- minimize CRT usage in ATL yes/no
- CLR support no/CLR
stdafx.h looks like this:
#if defined(_WIN32)
#ifndef WINVER // Allow use of features specific to #define WINVER
0x0501 // Change this to to target other
#endif
#ifndef _WIN32_WINNT // Allow use of features specific to
#define _WIN32_WINNT 0x0501 // (was 0x0501) Change to target other versions
#endif
#ifndef _WIN32_WINDOWS // Allow use of features specific to
#define _WIN32_WINDOWS 0x0410 // Change this to target Windows Me or later.
#endif
#ifndef _WIN32_IE // Allow use of features specific to IE
#define _WIN32_IE 0x0600 // Change this to target other versions of IE.
#endif
#define _ATL_APARTMENT_THREADED
#define _ATL_NO_AUTOMATIC_NAMESPACE
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
#include <atlbase.h>
#include <atlcom.h>
<---->
//#include <atlwin.h>
//#include <atltypes.h>
//#include <atlctl.h>
//#include <atlhost.h>
--> commenting these headers out did neither help nor hurt
using namespace ATL;
#import "progid:AerionInput.Device" embedded_idl no_namespace
#endif //_WIN32
The C# DLL is nothing spectacular and the "main" class(or the first one
being instanciated), which is not instanciated at this time. The COM-visible
interface looks like this:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace AerionInput
{
[
Guid("CB3BF65E-0816-482A-BB11-64AF1E837812"),
InterfaceType(ComInterfaceType.InterfaceIsDual)
]
public interface ISimpleDevice
{
int Type
{
get;
}
IKeyboard Keyboard
{
get;
}
ISensor Sensor
{
get;
}
void Connect();
void Disconnect();
void LoadPreferences(string preferencesName);
}
}
And the AssemblyInfo.cs reads this like:
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("TDxInput")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("n/a")]
[assembly: AssemblyProduct("TDxInput")]
[assembly: AssemblyCopyright("Copyright © n/a 2008")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(true)]
[assembly: Guid("7858b9e0-5793-4be4-9b53-661d922790d2")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
I am doing this on Windows 2000 with Visual Studio 2005 Pro latest SP and
.NET 2.0.50727 SP1.
Thanks in advance,
Christian
|
|
|
|
|
I have a VB.Net COM dll that I created and installed (using regasm) on a server. On this server is an application that calls different code modules based on events. One of those code modules calls the com dll which fires off and does a few things. If this process is kicked off from the server, everything works just fine. However, when the application is run from a workstation, the COM call fails. The workstation calls the code modules that reside on the server, the same ones that the server uses.
So why would the call to the COM object work fine on the Server, but when called through a workstation, to the server, fails out?
The CreateObject statement that creates the com object does not fail, but when called through the workstation, the call to the COM method fails.
Here's an example:
foo = CreateObject("Obj.Class")
result = foo.callMethod
The CreateObject works fine, but the foo.callMethod fails when it is kicked off from a workstation.
Anyone run into something like this before?
|
|
|
|
|
I would like to use the DECLSPEC_UUID and __uuidof operators to identify my record types.
In the IDLs I use constructs like:
typedef
[ uuid(....)
, version(1.0)] struct x {
...
} x;
Ok now MIDL creates in the header:
typedef DECLSPEC_UUID(....) struct x {
...
} x;
But the call of __uuidof(x) is invalid, as the order of DECLSPEC_UUID and struct has to be switched. So why does MIDL create this unusable code??
One possible solution is dropping typedef, but in each sample idl I saw before they allways used typedef with structures. Furthermore it is not possible to use the version-tag without the typedef.
Any Ideas??
|
|
|
|