|
hi me again, ive been writting code that fills a vector with random numbers from two sources, all even elements are filled from source1 and odd ones from source2...this now works fine after much debuggingmyhead.
ive been trying to to do next part of my function which is more complex, it basically uses a iterator with a const value of 0.002. which is 20millseconds.
this iterator goes to every single element in the array and goes through every element in 0.002 segments..i.e if element value is 3.6 then it goes through it in 1,800 segements. basically splitting up the element into segments,
and it does this to distingusih between numbers from sourceone and sourcetwo because these numbers are usesd elsewhere.. i will paste the code which fills the vector and ive COMMENTEDout the 'new' but it doesnt work imnot sure what else to do.
#include <iostream><br />
#include <vector><br />
#include <stdlib><br />
#include <time><br />
#include <numeric><br />
#include <algorithm><br />
#include "exponentialgenerator.h"<br />
<br />
using namespace std;<br />
<br />
ExponentialGenerator one = 1.41;<br />
ExponentialGenerator two = 1.71;<br />
<br />
double nextNumber = reinterpret_cast<double>(one.generate());<br />
<br />
double nextNumber2 = reinterpret_cast<double>(two.generate());<br />
<br />
int counter = 0;<br />
<br />
void fillVectorToSum(vector<double>& v, double sum)<br />
{<br />
<br />
int total = 0;<br />
do {<br />
if (counter++ % 2){<br />
v.push_back(nextNumber);<br />
total += nextNumber;<br />
nextNumber = one.generate();<br />
}<br />
else {<br />
v.push_back(nextNumber2);<br />
total += nextNumber2;<br />
nextNumber2 = two.generate();<br />
}<br />
<br />
} while(total+nextNumber+nextNumber2 <= sum);<br />
if(total < sum)<br />
v.push_back(sum-total);<br />
}<br />
<br />
<br />
int main()<br />
{<br />
<br />
srand((unsigned) time(NULL));<br />
vector<double> v;<br />
fillVectorToSum(v, 30);<br />
<br />
cout << "Number of elements: " << v.size() << "\nTotal: "<br />
<< accumulate(v.begin(), v.end(), 0) << endl;<br />
copy(v.begin(), v.end(), ostream_iterator<double> (cout," "));<br />
<br />
<br />
<br />
<br />
<br />
<br />
}
|
|
|
|
|
I have a project (MFC Application) in wich I need to insert an Windows Form. So, I've changed my project from unmanaged into managed.
Problem 1:
I have a control "Microsoft Flex Grid". When my project was unmanaged everything was OK. Now, I Have a "Debug Assertion Error" when i try to open the dialog box with the grid control.
Solution1: function AfxOleInit => Problem 2: Everything works ok but after I close the principal dialog box of the application = another Debug Assertion Error (in cmdtarg.cpp in "~CCmdTarget()"). If there is sb who had the same problem or who has a solution...thank you.
Monica
|
|
|
|
|
could you help me ?
How to custom drawing a window in managed C++ . I know about events, how to get DC, HWND and such, is it done this way ?
I lack msdn
thx in advance.
Robert
|
|
|
|
|
i want to put some text programatically from another application inside Yahoo Messangers instant message dialogue, my problem is i am unable to catch the RICHEDIT control inside the instant message window.
|
|
|
|
|
Hi for me you'll have use windows hooks. There's a nice article about subclassing on MSDN.
Try to read something about SetWindowsHookEx specially abaut CBT param of this function and SetWindowLong function. This will let you get a handle to Richedit control and its messages.
Pain is a weakness living the body
|
|
|
|
|
i am trying to send a text message from one application to yahoo instance messanger window but failing.
what i want is my application should send some text and that text should appear in the yahoo messangers instant message window.
please help me
|
|
|
|
|
This isn't really managed code,
This may not be possible, but the following could probably be done to insert messages into the "input text," but probably not the running chat:
- Use the Spy++ tool while an instance of YIM is running to find the YIM window class name and noting it, and finding the chat input child text box's id.
- In code, do a top level enumerations of windows to find the active YIM window, or alternatively, enumerate the user processes and find the process/main window.
- Get the handle of that "input text box" window
- Use that handle to set the window text.
If you're looking to add stuff to the running chat window, you may not be able to do so because it probably has text added by a method call somewhere internal to YIM.
|
|
|
|
|
Can anyone please direct me in the right direction. I am trying to find a prewritten program that will 'listen' for inputs from a serial port, and then launch an application. I'd appreciate any help.
kswisslk
|
|
|
|
|
Look for the article: "Use P/Invoke to Develop a .NET Base Class Library for Serial Device Communications" in the MSDN.
|
|
|
|
|
check out this:
http://www.codeproject.com/managedcpp/howtocomport.asp
...the mind is not a vessel to be filled but a fire to ignited
|
|
|
|
|
This one is good:
http://www.wcscnet.com
--Nikola--
modified 7-Dec-20 21:01pm.
|
|
|
|
|
How can I change the text (caption) color on CButton? I'm using a MFC dialog box.
|
|
|
|
|
Your object.SetWindowText("Caption"); ????
The returned pointer may be temporary and should not be stored for later use.
|
|
|
|
|
Hi,
I'm a bit vague on differences between managed C++ and unmanaged C++. Here's my problem:
#include "stdafx.h"
#using <mscorlib.dll>
#using<system.dll>
using namespace System;
using namespace System::IO;
using namespace System::Text;
using namespace std;
//using namespace System::IO::FileStream;
int _tmain(int argc, _TCHAR* argv[])
{
// TODO: Please replace the sample code below with your own.
string * fileName = &string(argv[1]);
FileStream *fs = new FileStream(fileName,FileMode::OpenOrCreate);
BinaryReader * w = new BinaryReader(File::Open(fileName, FileMode::Open));
return 0;
}
I get:
byteme.cpp(19) : error C2664: 'System::IO::FileStream::FileStream(System::String __gc *,System::IO::FileMode)' : cannot convert parameter 2 from 'System::IO::FileMode' to 'System::String __gc *'
Cannot convert an unmanaged type to a managed type
byteme.cpp(22) : error C2665: 'System::IO::File::Open' : none of the 3 overloads can convert parameter 1 from type 'std::string *'
stdafx.cpp(0): could be 'System::IO::FileStream __gc *System::IO::File::Open(System::String __gc *,System::IO::FileMode)'
while trying to match the argument list '(std::string *, System::IO::FileMode)'
And I was getting an issue with teh string * fileName declaration until I mangled some stuff...question is, what do these errors mean? And with MC++ do you use something other than argv/argc?
Charlene
|
|
|
|
|
try changing to....
String* fileName = new String(argv[1]);
|
|
|
|
|
ive been working on some simulation code, what i have written basically what it does it creates a Vector and fills it with random DOUBLE numbers from two different sources untill maz_size reached.. what im stuck is i want to go thorugh each element in the vector..prob using an iterator such as input_iterator i think?
so the vector is such..
[number_from_first_source, number_from_secondSource, number from_first source...etc etc]
so every odd element is form source1 and every even element is from source 2..
now i want to go thorugh each element with specific iterator value..example lets say 20ms i.e. 0.002..quite small value. the random numbers are all seeded values. so how owul di go through the vector with this small iterator value.
]#include <iostream><br />
#include <vector><br />
#include <stdlib><br />
#include <time><br />
#include <numeric><br />
#include <algorithm><br />
#include "exponentialgenerator.h"<br />
<br />
using namespace std;<br />
<br />
ExponentialGenerator one = 1.41;<br />
ExponentialGenerator two = 1.71;<br />
<br />
double nextNumber = reinterpret_cast<double>one.generate());<br />
double nextNumber2 = reinterpret_cast<double>two.generate());<br />
int counter = 0;<br />
<br />
void fillVectorToSum(vector<double>& v, double sum)<br />
{<br />
<br />
int total = 0;<br />
do {<br />
if (counter++ % 2){<br />
v.push_back(nextNumber);<br />
total += nextNumber;<br />
nextNumber = one.generate();<br />
}<br />
else {<br />
v.push_back(nextNumber2);<br />
total += nextNumber2;<br />
nextNumber2 = two.generate();<br />
}<br />
<br />
} while(total+nextNumber+nextNumber2 <= sum);<br />
if(total < sum)<br />
v.push_back(sum-total);<br />
}<br />
<br />
int main()<br />
{<br />
<br />
srand((unsigned) time(NULL));<br />
vector<double> v;<br />
fillVectorToSum(v, 30);<br />
<br />
cout << "Number of elements: " << v.size() << "\nTotal: "<br />
<< accumulate(v.begin(), v.end(), 0) << endl;<br />
copy(v.begin(), v.end(), ostream_iterator<double> (cout," "));<br />
<br />
}
the exponentialGenerator.h file i use jus to generate numbers if your wondering....
anyway any input to this problem would be appreciated.
|
|
|
|
|
i'm trying to accomplish something like this...
class ManagedClass;
class UnmanagedClass
{
protected:
void SetValue( std::string val );
friend void ManagedClass::SetValue( String* val );
};
namespace MyNamespace {
class __gc ManagedClass
{
protected:
void SetValue( String* val );
};
}
i can't get it to compile. i have tried just about every combination of the namespace and class name in the forward declaration and friend function definition. anyone have any ideas??
thanks.
|
|
|
|
|
I don't think you really need that friend directive. Most probably, you could simply make your classes public and avoid inline methods.
It seems that you want to call a managed method from an unmanaged class. However, this can't be done by a direct call, because managed objects are subject to garbage collection. To get a safe entry point into the managed heap, you have to use a GCHandle, which in turn is wrapped by the gcroot template. Try this:
#include <vcclr.h>
class ManagedClass;
class UnmanagedClass
{
public:
UnmanagedClass( ManagedClass* p );
private:
gcroot< ManagedClass* > m_pManaged;
}
You can then make your calls into the managed class with the m_pManaged pointer.
There might be another problem: Since you have both managed and unmanaged code in one project, this project needs to be linked in mixed mode. This is because for the unmanaged code, you need the C runtime, which requires an entry point as well as statics. For an instruction of how to convert your project to mixed mode, see the article: "Converting Managed Extensions for C++ Projects from Pure Intermediate Language to Mixed Mode" in the MSDN.
|
|
|
|
|
Is there a way to declare a function (SHOWME in this case) in C++ to prevent the name mangling so it can be referenced by C code.
I currently have this (form1.h):
public:
void showme(int thenum)
{
MessageBox::Show(S"abc", S"Result...");
}
|
|
|
|
|
Use extern "C" :
extern "C" void showme(int thenum)
{...}
|
|
|
|
|
Still get the same error.
|
|
|
|
|
The function called by the "C" module can not be a member of the class. One common way to export methods of a class for use by C code is to write functions (called wrappers) that take an object of the class as an argument. Here is a small sample :
<br />
<br />
extern "C"<br />
{<br />
<br />
int ShowMe( void *pobject, int argument )<br />
{<br />
CYourClass *pc = (CYourClass *)pobject;<br />
return pc->ShowMe( argument );<br />
}<br />
<br />
}<br />
<br />
I have done this on a fairly large scale and it worked rather well.
a two cent stamp short of going postal.
|
|
|
|
|
Well, progress is made. Any advice on appending text to a textbox in TOoutbox function. Here is the code:
#pragma once
extern "C" int magiccalc(void);
namespace myapp1
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
magiccalc();
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private:
System::Windows::Forms::TextBox * outBox;
private:
System::ComponentModel::Container * components;
void InitializeComponent(void)
{
...yada yada
}
public:
static void TOoutbox(int outnum)
{
outBox->AppendText("x"); //add text to textbox
}
};
}
extern "C"
{
void showme(int wrapnum) // My wrapper for C
{
myapp1::Form1::TOoutbox(3);
}
}
Thanks to all
|
|
|
|
|
myapp1::Form1::ioBOX.Appendtext("x");
Gives this error:
error C2228: left of '.Appendtext' must have class/struct/union type
type is ''
----------------------------------------------------------------------
Any ideas?
----------------------------------------------------------------------
#pragma once
extern "C" int magiccalc(void);
namespace myapp1
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
magiccalc();
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::TextBox * ioBOX;
private:
void InitializeComponent(void)
{
this->ioBOX = new System::Windows::Forms::TextBox();
... ...yadda yadda
}
public:
static void TOioBox(int outnum)
{
ERROR----> myapp1::Form1::ioBOX.Appendtext("x");
}
};
}
extern "C"
{
void showme(int wrapnum) // My wrapper for C
{
myapp1::Form1::TOioBox(3);
}
}
|
|
|
|
|
Name mangling is a technique used by the compiler.
Each compiler can have different algorithm for name mangling.
I don't think its possible to prevent name mangling.
Rahul
|
|
|
|