|
You seem to have more problems than function2 (thread2) reading from the comport more than once per second.
1) function1 does not need to be in a thread, it only reads once per second. Therefore, it can can be done in a OnTimer-(WM_TIMER) method.
2) How does function2 know that function1 is finished reading (or vis-versa)? Normaly you would set an event, that says, I have finished reading may data; then function(?) can read any data that it may be expecting to receive.
What you are describing is a nightmare, that I (am surprised) have not seen before. I do not know why one thread would be getting its data from 2 different ports (one shared) (again this smacks of poor design [which I assume was not yours]). In ether case both threads needs to know when the other thread has finished reading its data from the given port; they have to set an event (signaling that they are finished).
I wish I could help more, but, like I said, this makes no since. Who ever designed the origanal (COM) system, created a very bad design.
Good Luck!
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Use a Mutex, commeon to both threads. Should solve the problem.
|
|
|
|
|
#include <iostream>
#include <fstream>
using namespace std;
double** input_mat(int x,int y);
double** expand_mat(double** g,double** f,int d,int e);
void swap(double &m,double &n);
double** mult_row(double** q,double x1,int i1,int j1);
double** substract_row(double** w,int i2,int i3,int j2):
double** swap_row(double** s,int i4,int i5,int j3);
int main()
{
double** a;
double** b;
double** c;
double h,r;
int row,col;
cout<<"Enter the number of rows then coloumns of the matrix \n";
cin>>row>>col;
a=input_mat(row,col);
b=new double*[row];
for(int k=0;k<row;k++){
b[k]=new double[(2*col)];
}
b=expand_mat(a,b,row,col);
for(int j=0;j<col;j++)
{
if(b[(row-1)][j]!=0){
b=mult_row(b,b[(row-1)][j],(row-1),col);
for(int k=0;k<(row-1);k++){
b=mult_row(b,b[k][j],(row-1),col);
b=substract_row(b,k,(row-1),col);
}
b=swap_row(b,j,(row-1),col);
}
}
c=new double*[row];
for(int k1=0;k1<row;k1++){
c[k1]=new double[col];
}
ofstream out("Inverse");
if(!out){
cout<<"Cannot open file \n";
return 1;
}
for(int u=0;u<row;u++){
for(int v=0;v<(2*col);v++){
out<<b[u][v]<<endl;
}
}
out<<b[(row-1)][0]<<b[0][0]<<b[0][1]<<b[1][1];
return 0;
}
double** input_mat(int x,int y)
{
double** matrix;
matrix=new double*[x];
for(int i=0;i<x;i++)
{
matrix[i]=new double[y];
for(int j=0;j<y;j++)
{
cout<<"enter the element"<<j+1<<"in the row"<<i+1<<":";
cin>>matrix[i][j];
}
}
return matrix;
}
double** expand_mat(double** g,double** f,int d,int e)
{
for(int i=0;i<d;i++)
{
for(int j=0;j<e;j++)
{
f[i][j]=g[i][j];
}
}
for(int u=0;u<d;u++)
{
for(int v=e;v<(2*e);v++){
if((u+e)==v){
f[u][v]=1;
}else{
f[u][v]=0;
}
}
}
return f;
}
void swap(double &m,double &n)
{
double temp;
temp=m;
m=n;
n=temp;
}
double** mult_row(double** q,double x1,int i1,int j1)
{
for(int u1=0;u1<(2*j1);u1++){
q[i1][u1]=q[i1][u1]*x1;
}
return q;
}
double** substract_row(double** w,int i2,int i3,int j2)
{
for(int v1=0;v1<(2*j2);v1++){
w[i2][v1]=w[i2][v1]-w[i3][v1];
}
return w;
}
double** swap_row(double** s,int i4,int i5,int j3)
{
double temp1;
for(int u2=0;u2<(2*j3);u2++){
temp1=s[i4][u2];
s[i4][u2]=s[i5][u2];
s[i5][u2]=temp1;
}
return s;
}
please what is the wrong in this code???
please can any one answer me quickly
the compiler gives me these errors :
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(10) : error C2062: type 'double' unexpected
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(12) : error C2062: type 'int' unexpected
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(13) : error C2630: ';' found in what should be a comma-separated list
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(34) : error C2065: 'swap_row' : undeclared identifier
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(34) : error C2440: '=' : cannot convert from 'int' to 'double ** '
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(44) : error C2440: 'return' : cannot convert from 'const int' to 'double ** '
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(65) : error C2065: 'rtg' : undeclared identifier
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(65) : error C2143: syntax error : missing ';' before 'return'
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(101) : error C2084: function 'double **__cdecl substract_row(double ** ,int,int,int) ' already has a body
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(108) : error C2373: 'swap_row' : redefinition; different type modifiers
but i am sure i made thses rights for example
in the error:
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(34) : error C2440: '=' : cannot convert from 'int' to 'double ** '
in this error i am sure that the left hand side is defined as double** & the right handside is defined also as double** so how could it be wrong so acn anyone help me quickly bacause i have to disscuss this project with my doctor the next saturday so i need help quickly
By the way this program is to compute the inverse of a square matrix (n*n) using gauss elimination
srry but ther are some wrong things not from but from the net after i wrote the message it doesnt appear but i dont know why as the for loops it seems that it is not complete but i wrote it competely ut it doesnt appear when i preview the message but i dont know why
|
|
|
|
|
kosamoza wrote:
ut it doesnt appear when i preview the message but i dont know why
Check 'Do not treat <'s as HTML tags' below the message window and repost your code, and I'll be happy to throw it into a project to see what's wrong with it.
|
|
|
|
|
This is an example of a situation where one typo causes cascading errors for your compiler. Your forward declaration of substract_row ends in a colon (: ). Change it to a semicolon (; ) and everything will compile OK.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
The pre was a good idea but:
1) Replace the '<' characters with the '&' character followed by 'lt' (sorry, but the do not treat as HTML tags seems to be broken).
2) Replace the '>' characters with the '&'
character followed by 'gt'.
The fact that your functions are all returning double**, shows a major flaw in the design of your code.
From what I am seeing the functions should probabley be following this pattern:
data_type funct(data_type* data, etc...)
{
return(data);
}
Another example:
double* input_mat(int x,int y)
{
matrix *pMat = new matrix(x);
return(pMat);
}
Try to figure out why your design is flawed, then repost (if you need too); after fixing the '<' and '>' characters so we can see what is between them (and so we can try to cut/copy the code).
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
#include <iostream>
#include <fstream>
using namespace std;
double** input_mat(int x,int y);
double** expand_mat(double** g,double** f,int d,int e);
void swap(double &m,double &n);
double** mult_row(double** q,double x1,int i1,int j1);
double** substract_row(double** w,int i2,int i3,int j2);
double** swap_row(double** s,int i4,int i5,int j3);
int main()
{
double** a;
double** b;
double** c;
int row,col;
cout<<"Enter the number of rows then coloumns of the matrix \n";
cin>>row>>col;
a=input_mat(row,col);
b=new double*[row];
for(int k=0;k<row;k++){
b[k]=new double[(2*col)];
}
b=expand_mat(a,b,row,col);
for(int j=0;j<col;j++){
if(b[(row-1)][j]!=0){
b=mult_row(b,b[(row-1)][j],(row-1),col);
for(int k=0;k<(row-1);k++){
b=mult_row(b,b[k][j],(row-1),col);
b=substract_row(b,k,(row-1),col);
}
b=swap_row(b,j,(row-1),col);
}
}
c=new double*[row];
for(int k1=0;k1<row;k1++){
c[k1]=new double[col];
}
ofstream out("Inverse");
if(!out){
cout<<"Cannot open file \n";
return 1;
}
for(int u=0;u<row;u++){
for(int v=0;v<(2*col);v++){
out<<b[u][v]<<endl;
}
}
out<<b[(row-1)][0]<<b[0][0]<<b[0][1]<<b[1][1];
return 0;
}
double** input_mat(int x,int y)
{
double** matrix;
matrix=new double*[x];
for(int i=0;i<x;i++){
matrix[i]=new double[y];
for(int j=0;j<y;j++){
cout<<"enter the element"<<j+1<<"in the row"<<i+1<<":";
cin>>matrix[i][j];
}
}
return matrix;
}
double** expand_mat(double** g,double** f,int d,int e)
{
for(int i=0;i<d;i++){
for(int j=0;j<e;j++){
f[i][j]=g[i][j];
}
}
for(int u=0;u<d;u++){
for(int v=e;v<(2*e);v++){
if((u+e)==v){
f[u][v]=1;
}else{
f[u][v]=0;
}
}
}
return f;
}
void swap(double &m,double &n)
{
double temp;
temp=m;
m=n;
n=temp;
}
double** mult_row(double** q,double x1,int i1,int j1)
{
for(int u1=0;u1<(2*j1);u1++){
q[i1][u1]=q[i1][u1]*x1;
}
return q;
}
double** substract_row(double** w,int i2,int i3,int j2)
{
for(int v1=0;v1<(2*j2);v1++){
w[i2][v1]=w[i2][v1]-w[i3][v1];
}
return w;
}
double** swap_row(double** s,int i4,int i5,int j3)
{
double temp1;
for(int u2=0;u2<(2*j3);u2++){
temp1=s[i4][u2];
s[i4][u2]=s[i5][u2];
s[i5][u2]=temp1;
}
return s;
}
i have changed':' to ';' and it gives no error in the compilation but it gives the same prop;ems durin executing the programwhy?????
|
|
|
|
|
Hello,
I have created one software setup interface consisted of 5 wizard pages.
This interface has only 3 buttons Back , Next and Cancel + edit boxes on
each pages, where the user would type in the required data.
In addition to this interface,I have created one text file which has
the info. about the parameter.
The text file format is as follows:
IP1=xyz
Subnet1=xyz
Gateway1=xyz
[License]
ID=xyz
Identifier=xyz
License=xyz
[Pproperties]
Breaker=YES
Banking=NO
....................
Now, what I want to do is to export the user inputs in the edit box to the text file to the particular parameter when the user clicks the next button. For example, on page 3 Licence , the user will be required to type the ID and Identifier and Licence number. I want to have the data to be
written to the text file once the user is finished with setup. so that i can
use this text file again.
Can anyone help me out on this? Thanks a lot.
If you are willing to help , please explain in a detail. Thank you.
|
|
|
|
|
The format of your file matches that of .ini files, so you can try WritePrivateProfileString() and WritePrivateProfileInt() functions.
You can use GetPrivateProfileString() and GetPrivateProfileInt() functions to retrieve the data from the file.
Example:
WritePrivateProfileString("License", "ID", "xyz", "file.txt");
Hope that helps,
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Hi,
I am doing a project in vc++ win32. I want to run only one instance of exe at a time.If the user try to execute the exe when one is already running, I want to bring the one that is already running, to the top.
I am creating a mutex to check whether an instance of the app is already running thus preventing any further instance to run. But I want to know how to bring the one that is already running to the front. How do I get the handle of the window that is already running..pls help..
thanks a lot..
|
|
|
|
|
|
You could put some information that you wanted any subsequent instances of a program to read into a memory mapped file. The first instance to run writes the data, like a window handle, and the others can read it when they figure out they are not the first instance, and they can use that data for whatever purposes, such as activating the existing window.
When my first instance runs, I write the window handle the process ID and the primary thread ID to the memory mapped file.
I also left room to store a file path, in case the second instance was activated with a file path on the command line, I can store the file path in the memory mamped file and then activate the first instance by posting its main window a special message. the first instance can attempt to load the file specified by the 'new' instance, since sometimes this happens when user is clicking files in Explorer and your program is already running.
|
|
|
|
|
Hi,
I was wondering if there are any message map entries for right clicking on an entry in a drop down CComboBox control? I'd like to take an action if a user right clicks on an entry. Thank you very much =)
Jay
jaycush@bellsouth.net
|
|
|
|
|
Hi, wrote a dll( MFC dll static lib ): Mydll project:
in the Mydll.cpp: I add a entry function: Fun1(), But
when use rundll32 Mydll Fun1 Command I got error message
" Error in Mydll Missing Entry:Fun1". What is the reason???!!!
BEGIN_MESSAGE_MAP(CMydllApp, CWinApp)
//{{AFX_MSG_MAP(CMydllApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMydllApp construction
CMydllApp::CMydllApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
CMydllApp theApp;
extern "C" BOOL PASCAL EXPORT Fun1()
{
.....
return 1;
}
|
|
|
|
|
From a command line, verify the function really got exported with the name you are expecting by using this:
DumpBin /Exports MyDll.Dll
You should see the Fun1 in the list. If not, the function never 'escaped' from your DLL.
|
|
|
|
|
Dump of file MyDll.dll
File Type: DLL
Section contains the following exports for MyDll.dll
0 characteristics
42B9E5A6 time date stamp Wed Jun 22 18:26:46 2005
0.00 version
1 ordinal base
1 number of functions
1 number of names
ordinal hint RVA name
1 0 0000100A _Fun1@16
Summary
7000 .data
1000 .idata
3000 .rdata
2000 .reloc
2A000 .text
|
|
|
|
|
It is almost like your DLL does not have the DllMain 'entry point' that windows needs to call to load it.
Did you start with a generic DLL or a generic MFC DLL project? If so, that is strange, if not, then you need to add a DllMain to your DLL project.
|
|
|
|
|
I cretae the project by Visuasal Stadio Vizard.
New=>MFC DLL=>... See the file
// MyDll.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "MyDll.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
/////////////////////////////////////////////////////////////////////////////
// CMyDllApp
BEGIN_MESSAGE_MAP(CMyDllApp, CWinApp)
//{{AFX_MSG_MAP(CMyDllApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDllApp construction
CMyDllApp::CMyDllApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMyDllApp object
CMyDllApp theApp;
extern "C" __declspec(dllexport) void CALLBACK Fun1(HWND,
HINSTANCE,
LPTSTR lpCmdLine,
int)
{
int i;
i = 1;
}
|
|
|
|
|
When I look at similar entries in the registry, I notice ALL the ones I saw have a comma in between the name of the DLL and the function name.
Instead of
rundll32 Mydll Fun1
why don't you try
rundll32 Mydll.dll,Fun1
|
|
|
|
|
Are you needing the temporary file simply so that the two applications can communicate?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
|
Hi all,
This may be an anal question, but...
I've inherited some code where the original programmer would go through the hassle, for example, of doing an OS check before opening every single registry key the program looks at, eg, if it's VER_PLATFORM_WIN32_NT, then a "SOFTWARE\[whatever]" string is built, and if it's running on Win9x, then the string is "software\[whatever]".
My own tests and experience tell me that opening any key for reading should NOT be case-sensitive. I'm tempted to modify the code and hardwire "SOFTWARE" everywhere, to save the overhead in (a) calling the function and (b) building different strings.
My question...is anyone aware of any circumstances where my change would actually cause failures?
Note that I do understand the difference between creating a new key in lowercase vs uppercase...but I'm talking here strictly about opening existing keys for reading only...
|
|
|
|
|
Daniel Desormeaux wrote:
My question...is anyone aware of any circumstances where my change would actually cause failures...but I'm talking here strictly about opening existing keys for reading only.
I've used mixed-case successfully.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Daniel Desormeaux wrote:
My question...is anyone aware of any circumstances where my change would actually cause failures?
For Last 1 yr, I have used registy in almost each of my project and almost each of Window Platform ranging from 95 to XP, I believe, I never face problem with case sensitivity
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
In .Net, you can retrieve the code page for a given character encoding as follows:
<br />
Encoding blah = Encoding.GetEncoding("utf-7");<br />
<br />
Is there a similar function in Win32 or MFC?
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|