|
Ok thnx now it's all clear, although it doesn't make my life easier...
|
|
|
|
|
Hello,
I have an MC++ class exposing a COM interface ISrv. MC++ class also has a source interface, ISrc.
ISrv has below method:
void AttachSink( [MarshalAs(UnManagedType::IUnknown)]Object* pSrcUnk,
Int32 *pError, Int32* pState);
I have MFC sink class (derived from CCmdTarget) and implements ISrc interface.
Native C++ application instantiates this sink class and passes the sink object to MC++ by calling above method.
During CTRL+C operation, when sink object is destroyed , CCmdTarget throws an assertion at line:
ASSERT(m_dwRef <= 1)
In the debugger I found m_dwRef as 3. If this call is commnented then the assertion doesn't fail.
Debugging info:
I kept some "cout" statements within Sink class in side overridden method, QueryInterface().
I observed that QI was called 3 times in excess when the above method was called in my native application.
Actually, I call QI only once (right after Sink object instantiation) to retrieve ISrc interface.
Therefore, I presumed that it may be CCW invoking QI those many times and incrementing reference count. Is this correct?
Can you please let me know how to get around this problem of incorrect reference count?
I observed this problem only when this method was called. I call many other methods of MC++ class. But those methods do not take pointer to IUnknown as their parameter.
Does CCW behave different when IUnknown * is marshalled.
Is it likely that it does auto increment of reference count?
PLEASE SEE: I called Marshal::ReleaseCOMObject() in MC++ class and it returned reference count as 1. However, during the destruction of Sink object, ASSERT still popsup.
Looking forward your response....
Thank you and best Regards,
-- modified at 14:44 Thursday 16th February, 2006
|
|
|
|
|
Ok........how do I even begin this? What should the header file look like? Then how do I put everything together in the cpp file? I need HELP!!!
You are to create a student record object. The info about the student is below:
Last Name
First Name
Social Security Number (Format: XXX-XX-XXXX)
Current Class Designation (Freshman, Sophomore, Junion, Senior)
Three Separate Grades (Floating Point – Range 0.0 - 100.0)
You should use a class to represent the student record object. Your class should include the following:
A Default Constructor (all values intialized to zeros or nulls)
A Constructor for a student's entire data
A Destructor (must display a notice when an object is destroyed)
A method to add/change a student's data
A method to determine a student's final grade (Average of the three separate grades)
A method to print a student's data, including the final grade (represented as a double)
|
|
|
|
|
This is definitely a homework assignment. We are here to help you go to the next stage, but not provide complete solutions.
You'll find countless examples on Google about this (creating class, public accessors and modifiers, constructors, destructors, variable declaration & initialization, etc). Try it out on your own first and then ask for help if you get stuck.
And post specific questions and not the assignment text posted by your instructor.
- Malhar
|
|
|
|
|
Any help would be gratefully received. You should see from my email address that I'm not trying to get "homework" done for them, in fact this program will be used in QA of clinical treatments so it's vey useful!
I was a programmer for 3-4 years for Infogrames (games), mainly working on export tools for 3D Studio Max, working with the Max SDK and Win32/MFC dialog apps for artists. I learnt programming on the job, and never really had any background knowledge, so I wasn't going to win any awards for my code, and I certainly didn't have the skills to go beyond the stuff I worked on routinely.
I've been away from coding for a while but now I need to get back into it as part of my job here, after a break of 4 or more years. I'm trying to get some good books and learn *properly* the C++ language from the ground up to get the basics, but this project needed to be done a.s.a.p
I did get the program to work with an MFC dialog (see below) but it's very ugly and I can already see "sort of" how it should be done properly with a class or two, maybe even use STL, but I wanted to ask if anyone could spare the time to suggest a good way to deal with it, even just in design terms (though code snippets would be great also!)
Here is the file format which is exported from a medical instrument.
Measurement Export Matrixscan 1.1
Date: 20/01/2006 11:47:01
Cols:27
Rows:27
Measurement Values:
2.314591E-02;2.654959E-02;2.981629E-02;
I've trimmed the values, in actual fact it can be up to 27 rows of 27 items, separated by semi colon (and not always square array!)
What my program is doing in a very ugly way is using Getline on a file stream to read in each line bit by bit, using colon separators at first to get the header info, then using semi colons on the data after creating a new float array.
At the moment I'm only reading in the central row and column into 2 separate arrays (but I'm going to change that to read the whole array and then be able to process any row or column)
For each of the two arrays thus extracted I have to:
- use the centre point as the 100% value
- work out 50% value, and using interpolation, work out which fractional array index that refers to to get an effective field size, eg, if the 50% value is between array[3] and array[4], I interpolate to get an answer of 3.xx. This occurs in two places, one before and one after the centre point (these are 2D profiles shaped like a top hat but with a dip in the middle of the profile).
- Once I have the field size for each array, I work out 80% of that field size, and then have to work out which elements in the array fall within those values, so if I get a field size of 21.1 cm (each array element in the data is 1 cm apart), that means 10.55 either side of the middle element, so I would include only the 10 elements each side of the centre
* upgraded this bit to do the same but using the whole 2D array
- I then go along each row/column and look at corresponding data points equidistant from the centre. Eg, if array[13] is the middle of a 27 sized array, I compare array12 and array 14, array11 and array15, to work out the biggest ratio between those pairs, and which side of the centre it occurs
- I also work out the highest and lowest value in the whole array within the 80% section of the 50% region (relative to the centre point)
I have this as an MFC Dialog which uses CFileDialog to open a list of files (OFN_MULTISELECT) then a process button to process the selected file, which is all done in one big block top to bottom in a single function, with no real error checking and I'm sure lots of redundancy
I have a feeling a better way to do this would be to have a 2DArray type class, with array data and header details, have functions to load and process this data, perhaps have more generic file import class? and also more generic array processing to allow me to "get" a specific element, row or column from the 2D array which I currently store as a 1D array and use indexes to look up a specific cell
I hope that makes sense, any comments or feedback welcome, and you can email me if you want to discuss further
cheers,
lee
|
|
|
|
|
Sorry wrong forum, moved to Visual C++
|
|
|
|
|
|
First of all, you should check "Ignore HTML tags in this message..." check-box. Some of your code is obscured. Second, this appears to be a C++ question and not a C++/CLI question.
|
|
|
|
|
I want to save an image to a MySQL database. I think I need to use a MemoryStream to do this. Here is a sample that doesn't work:
Bitmap ^ MyImage;
MyImage = gcnew Bitmap(pictureBox1->Image);
MemoryStream ^ MyStream = gcnew MemoryStream;
MyImage->Save (MyStream, System::Drawing::Imaging::ImageFormat::Jpeg);
String ^ InsertString;
InsertString = String::Format ("insert into blobtest (blobtest) values ('{0}');", MyStream->GetBuffer());
MyStream->GetBuffer() just returns "System.Byte[]", not the actual data, which is what I want. You can see what I'm trying to accomplish here. Why isn't it working?
|
|
|
|
|
You cannot pass this type of data using SQL injection. You need to create a database parameter and set it to the value of your MemoryStream before executing your insert.
|
|
|
|
|
Can someone tell me why the System::Web::UI stuff was left out of C++/CLI? Not like we couldn't use C++/CLI to write some web components or anything!
And just because C++/CLI doesn't support partial classes?? So what! Why can't we use C++/CLI to develop web sites!
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
|
|
|
|
|
You can use C++/CLI to develop web sites! You can access C++/CLI assemblies without any problems as far as I know. Furthermore, System::Web is accessible!
-- modified at 18:54 Tuesday 14th February, 2006
|
|
|
|
|
You don't have access to System::Web::UI at all. Not even included in the release. Kinda like a book with a few chapters left out!
So yes you can use C++/CLI assemblies but with restrictions for what you use them for.
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
|
|
|
|
|
What version of Visual Studio do you have?\
|
|
|
|
|
VS 2005 Pro
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
|
|
|
|
|
According to Nishant Sivakuma, and I quote him: "For inline code and for code-behind, you have to use either C# or VB (both are similar languages). But you can put most of your core code in managed or mixed-mode DLLs written in C++." This was taken from the Visual C++ Language Message Board on msdn.microsoft.com.
Also, after referencing the System.Web.dll, I was able to access a few web controls and process their data using a C++/CLI assembly.
-- modified at 21:39 Wednesday 15th February, 2006
|
|
|
|
|
Here is a trivial example:
// AspCppCli.h
#pragma once
#using <System.Web.dll>
using namespace System;
using namespace System::Web::UI::WebControls;
namespace AspCppCli {
public ref class CppCliTest
{
public:
void InsertGreeting(TextBox ^% tb)
{
tb->Text = "Hello, World!";
}
};
}
-- modified at 22:10 Wednesday 15th February, 2006
|
|
|
|
|
AH!
#using <System.Web.dll>
That makes a difference!
But! Still my point....why do we have to do that!
Thanks for getting me going!!
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
-- modified at 16:16 Thursday 16th February, 2006
|
|
|
|
|
Actually, I feel just like you about this. This kind of makes C++/CLI a second class citizen of managed code.
|
|
|
|
|
Hi,
I need to implement the multi-threading using C++(Not VC++). What are the options available fot it.
Thanks in advance.
Regards
Mahesh
|
|
|
|
|
|
Actually, I wonder why there is no C++ forum here. If he posts the same question in "Visual C++" forum, people will complain that it is not Visual C++ question. If he posts it in here, people still complain that it is not a Managed C++ forum. Poor C++ programmers...
As to the question, you have to use _beginthreadex and _endthreadex. These functions are in C++ standard library and they know how to free the resources of your threads. Don't use beginthread and endthread because they are obsolete. Neither should you use windows CreateThread and ExitThread because Win32 functions don't know about C++ library and may not be able to free the resources adequately.
As a reference I would recommend Jeffrey Richter "Programming Applications for Microsoft Windows". He talks about multithreading, multiprocessing, memory structure (very interesting things like Address Windowing Extensions), exceptions, and other useful stuff. It may be difficult to find this book though. Amazon does not sell it any more.
|
|
|
|
|
RainbowWyrm wrote: I wonder why there is no C++ forum here
the question is legitimate.
consider the fact though that you are on CodeProject on a web site dedicated to the Microsoft development technologies... (Visual Studio, etc...)
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
|
|
|
|
|
Yeah, but sometimes, you got to stay platform-independant while still working in Visual Products (though that kinda limits you to C++).
For starters: I got MS VC++ 2005 Express. I use it to develop a OpenSource-Qt freeware tool.
If I have Qt-questions, I AM gonna ask them in a Qt-Forum, but if I am stuck with VS-Problems or Standard-C++ issues, I'd rather ask on CodeProject.
|
|
|
|
|
Sebastian Schneider wrote: if I am stuck with VS-Problems or Standard-C++ issues, I'd rather ask on CodeProject
yeah... that's what the Visual C++ forum is for...
C++/CLI forum is for managed C++ (you know, thet stufs for the .NET framework....)
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
|
|
|
|
|