|
Thanks.
It seems like the application is never allowed to start once the logout process has started on XP (which was apparently not the case under NT4). So I guess I have to make an app that starts att login and runs the whole time the user is logged on and finally does the work it is intended to just before it is shut down. Of course the app can not be allowed to take any cpu while waiting to be shut down.
Do anyone have a better idéa or can you recommend any articles or similar on the subject? How do I best implement the application? I haven't really implemented any event controlled applications in C++ before (appart from forms and console applications, but I can't have a form or console open and visible in this case).
Thanks
/EnkelIk
|
|
|
|
|
I'm trying to use an existing COM object from within .NET and am having problems passing a parameter than used to be of type VARIANT.
I have a COM interface, IScanner with the following method:
virtual HRESULT __stdcall GetOptionDetails (
/*[in]*/ long lOption,
/*[in,out]*/ VARIANT * pVarBuffer,
/*[out,retval]*/ long * plResult );
where the variant, pVarBuffer, will contain one of a variety of structures, including:
struct IMAGE_OPTION_DETAILS
{
long lSequenceNumber;
long lGreyScaleSupported;
long lVResolution;
long lHResolution;
long lBitDepth;
};
The following code shows how the structure was previously converted to a variant and passed to the interface:
void GetUdtRecordInfo(const TCHAR *tszName, IRecordInfo** ppRecInfo)
{
// Use Macro for easier unicode conversion
USES_CONVERSION;
ITypeLib FAR* pITypeLib;
ITypeInfo FAR* pITypeInfo;
HRESULT hr = LoadRegTypeLib(LIBID_PSCLASSICLib, 1, 0,
GetUserDefaultLCID(), &pITypeLib);
if (hr != S_OK)
THROW_ERROR("Failed to load type library");
// Retreive the IRecordInfo from the ITypeInfo interface for the first (and only) occurance
// of the type in the type library
USHORT nFound = 1; // number of occurances to look for
MEMBERID mID[1]; // array to store the MEMBERID of the type. Must be same size as nFound
hr = pITypeLib->FindName(T2OLE(tszName), 0, &pITypeInfo, mID, &nFound);
if (hr != S_OK)
THROW_ERROR("Failed to find the name of UDT.");
hr = GetRecordInfoFromTypeInfo(pITypeInfo, ppRecInfo);
if (hr != S_OK)
THROW_ERROR("Failed to get the Record Info of UDT");
// Release interfaces
pITypeInfo->Release();
pITypeLib->Release();
}
void ConstructRecordVariant(IRecordInfo* pRecInfo, LPVARIANT pVariant, void* pStruct)
{
VariantInit(pVariant);
V_VT(pVariant) = VT_RECORD | VT_BYREF;
V_RECORD(pVariant) = pStruct;
pVariant->pRecInfo = pRecInfo;
}
int _tmain()
{
IMAGE_OPTION_DETAILS details;
VARIANT var;
IRecordInfo* pRecordInfo = NULL;
CString sTypeName = "IMAGE_OPTION_DETAILS";
void* pStruct = &details;
// Construct the VARIANT data structures for the detail, in and out data.
GetUdtRecordInfo(sTypeName, &pRecordInfo);
ConstructRecordVariant(pRecordInfo, &var, pStruct);
// now we make the call to the COM interface
HRESULT = pIScanner->GetOptionDetails(IMAGE_FRONT, &var);
return 0;
}
In DotNet, the COM object is wrapped into a class with the above method converted to:
public int GetOptionDetails(int lOption, ref object pVarBuffer);
My question is how do I pass the converted version of the above structure to this method? I tried the obvious
ScannerClass * scanner = new ScannerClass();
IMAGE_OPTION_DETAILS details;
Object* obj = __box(details);
scanner->GetOptionDetails(
SCANNER_OPTIONS::IMAGE_FRONT,
&obj);
but this failed with:
"A first chance exception of type 'System.ArgumentException' occurred in PSTest.exe"
"Additional information: The specified record cannot be mapped to a managed value class."
Any help would be much appreciated!
Mike.
|
|
|
|
|
Hi all
I have an MFC class named CCoordWnd derived from CWnd. Now I'm porting this
class to .Net.So,I started with deriving from class
System::Windows::Forms::UserControl.
My MFC class CCoordWnd have overloaded constructors like these.
CCoordWnd(unsigned int cnum,CCoordWnd **myptr);
CCoordWnd(CCoordInterface *cip,CCoordWnd **myptr);
CCoordWnd(CCoordInterface *cip,unsigned int cnum,CCoordWnd **myptr);
and a member variable like this.
CCoordWnd ** m_myptr
Can anybody help me how can I implement these functionality in ManagedC++ environment.This is very urgent work for me.Please help me.
Thanks in Advance
Regards
Krishna
|
|
|
|
|
Here's the problem I'm facing: I have a hierarchy of classes:
class button;
class bitmap_button : public button;
class text_button : public button;
Now I want to wrap this is managed c++. How should I do this ?
Jonathan de Halleux.
|
|
|
|
|
Probably something like:
class __gc managed_button {button* bt_;...};
class __gc managed_bmp_button : public managed_button {bitmap_button* bmpBt_;...};
|
|
|
|
|
|
Is it possible to use a form written in C# in my MC++ app? I don't want to have to create the form programaticaly because it has quite a few controls on it. I added a Windows Form project to my solution and created the form, but I've no idea how I reference it in my MC++ app. I tried simply using Namespace::Classname , but that failed. Would I have to compile the form into a dll so I can reference it? If so how would I do that?
Thanks for the help.
- monrobot13
|
|
|
|
|
It would have to reside in a dll. You would just compile it as you would a normal dll. You could either reference it with a project reference, or with a reference to the dll binary.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Thanks for the reply. I acutally did get it working compiling it as a dll, but I have another question now. In order for it to work I have to copy the dll to the same directory that my exe excutes in. This is a royal pain and I know it's the wrong way to do it. I want to know how I can get the exe to use the dll from the location the dll is build to or how I can automatically have VS.NET copy the dll to the exe directory when it's built.
Thanks again.
- monrobot13
|
|
|
|
|
Well, I don't know about VS.NET, but I use SharpDevelop, and it allows you to specify scripts to run before and after a build.
Another thing you could do is to change the output directory to either the same directory as the exe, or a subdirectory under the exe directory, named the same name as the dll (w/o the ".dll" part).
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I'll see what I can do. Thanks for the help.
- monrobot13
|
|
|
|
|
I'm new to this myself, but isn't that what the
#using <drive:\path\filename.dll>
syntax is for?
|
|
|
|
|
In the VS.NET environemnt, right click your project and select "Properties", this will bring up the property dialog for that project.
Expand the "Build Events" leaf, and then select the "Post-Build Event" item.
In the Command Line box, enter something along the lines of:
copy "$(TargetPath)" ..\bin\debug\
Where ..\bin\debug (just taken from one of my projects) is the fully-qualified or relative path to where you want the file to be copied after successful compilation/linking. Note that in my example, I have separate output directories for debug/release builds and so copy to different directories. You may just have one directory for both configurations, and if so should select "All configurations" from the "Configuration" drop-down prior to entering the line above.
Hope that helps.
Ben
--
When it comes to maths and me, the wheel's going but the hamster's dead.
|
|
|
|
|
Thanks for help. I figured it out after about 10 minutes or so of fumbling around in the properties.
- monrobot13
|
|
|
|
|
I've almost completed my first custom control, however I can't find out how to modify the vairables at design time by appearing in the Properties dialog in form view.
Could anyone tell me how to do it?
Thanks
|
|
|
|
|
Which of the following takes more CPU cycles?
(a) if(i==j)
(b) i*j
Thanks!
norm
|
|
|
|
|
|
With new processors, pentium or better, this is not a question with an exact answer. The answer both may take 1 cpu clock or as many as the length of the integer pipeline - 2 instructions on the cpu. For Athlons this maximum is 10 clocks. For P4 cpus this maximum is 18 clocks. Each integer instruction has to go through the entire pipeline but if there is no register or memory dependence the next instruction will be started on the next cpu cycle. On p4 this will be 1/2 a clock because the p4 alu runs its pipes 1/2 a clock apart so in effect it runs them at 2 * the cpu frequency. A branch misprediction on either procesor will cause the entire pipeline to have to be emptied so in effect the next instruction may have to wait as long as the length of the pipeline - 2 instuctions.
[EDIT]
Now to answer the original question. If either I or J are random than B is always faster. If the answer (i==j) is false or true over 90% than A is probably faster unless J*I has no register dependence on the next or previous calculation. If this is the case B is always faster.
[/EDIT]
John
|
|
|
|
|
Assuming the compiler uses the same method to access i and j in both cases:
(a) compiles into a compare (a subtraction) and a conditional jump instruction.
(b) compiles into a multiplication instruction.
Depending on the processor and the values of i and j , (a) may actually take more CPU cycles.
Software Zen: delete this;
|
|
|
|
|
Destructors won't execute until an object is deleted -- which may not happen for a while in managed projects. Is there any function you can write to have called immediately when the last reference to an object is removed?
Thanks
READIN writin rhythmetic
|
|
|
|
|
Jeremy Osner wrote:
Is there any function you can write to have called immediately when the last reference to an object is removed?
No.
You can manually force the destructor to be called by explicitly calling the delete operator on the reference object. However, while the destructor method will execute (which may be enough in certain cases where your main concern is performing clean-up chores), the memory allocated for the object will not actually be freed till the next garbage collection cycle.
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
There is no such thing as C++ destructors, but you can wrap a __gc class into a __nogc one that can implement reference counting for you.
|
|
|
|
|
Nemanja Trifunovic wrote:
There is no such thing as C++ destructors
I'm assuming you mean that there are no destructors in managed classes since we've used destructors in native classes for years. Even then, yes, there are destructors in managed C++ and as I noted in my reply to the original post you can explicitly call them.
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
Yes, wrong wording, sorry. What I meant is that we don't have destructors in __gc classes. We only have functions that look like destructors, but they are really finalizers, not real destructors.
|
|
|
|
|
True. However, even then we're talking a really fine line of differentiation as C++ .NET reference object destructors are invoked when the object is deallocated and can be manually invoked via the C++ delete operator.
Krista
"Who doesn't bend before the wind is mighty apt to break."
Author Unknown
|
|
|
|