|
Hello !
I was having some troubles with the use of COM ports on an embedded device (Pocket PC with windows mobile 5). I already opened a discussion here[^].
I finally decided to use WaitCommEvent to monitor incoming data but this doesn't seem to work as expected. The port that I'm working with is a virtual COM port which is provided by a Bluetooth stack when a Bluetooth connection is established. Here is the code:
int CSerialDriver::ReadData(char* szData, int MaxLenght)
{
DWORD dwMask = 0;
WaitCommEvent(m_hCOMPort,&dwMask,NULL);
if (dwMask & EV_RXCHAR)
{
DWORD dwRead = 0;
int Count = 0;
do
{
Count = MaxLenght - BytesRead;
ReadFile(m_hCOMPort,szData+BytesRead,Count,&dwRead,NULL);
BytesRead += dwRead;
} while ( dwRead && (BytesRead<MaxLenght) );
}
return BytesRead;
}
The comm mask is set when the port is opened:
SetCommMask(m_hCOMPort,EV_RXCHAR);
The problem that I encounter is that the WaitCommEvent doesn't work as expected: when I receive data, WaitCommEvent exit as expected but sometimes, all the data has not been received yet (which is logical). That's not a problem because my function will get called until all data has been received. The problem comes when I enter the function a second time and call WaitCommEvent, at this time it doesn't exit even if bytes have been received in between. Having read this article[^], WaitCommEvent should exit if bytes have been received in between.
Would it be possible that it is a bug in the driver supplied by the company that produce the Bluetooth stack ? Or did I do something wrong ?
Another question: it is stated in MSDN:
Only one WaitCommEvent can be used for each open COM port handle. This means that if you have three threads in your application and each thread needs to wait on a specific comm event, each thread needs to open the COM port and then use the assigned port handle for their respective WaitCommEvent calls. (see here[^])
So, that would mean that your application could open the COM port several time. I tried that on win32 but that doesn't work at all (each time I receive an invalid handle value and the GetLastError code is "Access is denied"). I tried with different access:
m_hCOMPortWrite = CreateFile(strPortName.c_str(),
GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
m_hCOMPortRead = CreateFile(m_strPortName.c_str(),
GENERIC_READ ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
Is there a difference here between win32 and windozs Mobile 5 ? Why do they state that you could open the port multiple time ?
Thanks in advance
|
|
|
|
|
//Its tt.java simple Helloworld program .which i am willing to call from c++
// i created .class and .h file of it !
public class tt {
public static void main(String[] args) {
System.out.println("Hello World ");
}
}
//*****************************************************************************************
//i wrote it in vc++ 6.0
//for this i added path of tt.h(created using javah) in preprocessor path(underprojects=>setting=>c/c++ tab)
//then added path of jvm.lib (under projects=>setting=>link tab)
#include "jni.h"
#define PATH_SEPARATOR ';' /* define it to be ':' on Solaris */
#define USER_CLASSPATH "C:\j2sdk1.4.2_05\bin" /* where tt.class is */
int main()
{
JNIEnv *env;
JavaVM *jvm;
jint res;
jclass cls;
jmethodID mid;
jstring jstr;
jclass stringClass;
jobjectArray args;;
JavaVMInitArgs vm_args;;
JavaVMOption options[1];
options[0].optionString ="-Djava.class.path="USER_CLASSPATH;
vm_args.version = 0x00010002;
vm_args.options = options;
vm_args.nOptions = 1;
vm_args.ignoreUnrecognized = JNI_TRUE;
/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
if (res < 0) {
fprintf(stderr, "Can't create Java VM\n");
// exit(1);
}
cls = (env)->FindClass("tt");
if (cls == 0) {
// goto destroy;
}
mid = (env)->GetStaticMethodID(cls, "main","([Ljava/lang/String;)V");
if (mid == 0) {
// goto destroy;
}
jstr = (env)->NewStringUTF(" from C!");
if (jstr == 0) {
// goto destroy;
}
stringClass = (env)->FindClass("java/lang/String");
args = (env)->NewObjectArray(1, stringClass, jstr);
if (args == 0) {
// goto destroy;
}
(env)->CallStaticVoidMethod(cls, mid, args);
//destroy:
if ((env)->ExceptionOccurred()) {
(env)->ExceptionDescribe();
}
(jvm)->DestroyJavaVM();
return 0;
}
/// After doing that much ! i got this LINKING TIME ERRORs
--------------------Configuration: ltry - Win32 Debug--------------------
Compiling...
Skipping... (no relevant changes detected)
tr.cpp
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/ltry.exe : fatal error LNK1120: 1 unresolved externals
// please help me sir....what chages i should do so that it gets run n calls java method ?
|
|
|
|
|
You probably are trying to create a Win32 application and you provide a main function instead of a WinMain. You should create a console application instead.
|
|
|
|
|
See here.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi all,
I am new to VC++, I am developing an dll file using VC++, in this i want to put an entry in my windows registry. For example:
SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\test\\test , in this path i want to write some value in the key test.
Plese suggest me
Thanks in advance
Know is Drop, Unknown is Ocean
|
|
|
|
|
Use RegCreateKeyEx for creating the path in the registry, the second parameter is where you'll set the path that you said. You can create the values in your registry by using RegSetValueEx. RegCloseKey will close the registry item that you opened.
|
|
|
|
|
Thanks for your suggestion. Dnt mistake me, plz give me some sample code's or link to learn this.
Thankyou once again
Know is Drop, Unknown is Ocean
|
|
|
|
|
|
Thankyou very much for your kindly help
Know is Drop, Unknown is Ocean
|
|
|
|
|
Exelioindia wrote: plz give me some sample code's or link to learn this.
Is that something you are incapable of?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
You can also try for -
CWinApp::WriteProfileInt/CWinApp::WriteProfileString and CWinApp::GetProfileInt/CWinApp::GetProfileInt
|
|
|
|
|
Thanks for your suggestion. Dnt mistake me, plz give me some sample code's or link to learn this.
Thankyou once again
Know is Drop, Unknown is Ocean
|
|
|
|
|
|
for me CRegKey class provided by Atl is best!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Use below function
BOOL WriteToRegistry(HKEY hRegRootPath, CString strRegPath, CString strRegAttribute, long lValue)
{
CRegKey key;
CString strAttributeValue;
strAttributeValue.Format("%u", lValue);
if(key.Create(hRegRootPath, strRegPath) == ERROR_SUCCESS)
{
if (key.SetValue(strAttributeValue,strRegAttribute) == ERROR_SUCCESS)
{
key.Close();
return TRUE;
}
}
return FALSE;
}
call the function as shown in example below...
WriteToRegistry(HKEY_LOCAL_MACHINE, "SOFTWARE\\ABC\\DEF", "NUM",1);
Rahul Vaishnav
|
|
|
|
|
Thanks for your code. I am getting some error with the above code. Is this an VC++ code?, sorry if i am wrong.
Errors:
error C2061: syntax error : identifier 'CString'
error C2065: 'CRegKey' : undeclared identifier
error C2065: 'CString' : undeclared identifier
error C2065: 'key' : undeclared identifier
error C2065: 'lValue' : undeclared identifier
error C2065: 'strAttributeValue' : undeclared identifier
.............
Any header files has to included?
Thankyou once again
Know is Drop, Unknown is Ocean
|
|
|
|
|
Exelioindia wrote: Is this an VC++ code?,
If you have to ask such a question, then a project involving the registry is way beyond your grasp. Start with something less ambitious, please!
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
Californian2 wrote: He's rude to everybody...
If my bluntness offends you, ignore it. You'll find that my sentiments (toward newbie laziness) are supported by the professionals. If I said something that was indeed incorrect, I'll admit such, and have done so in the past.
Californian2 wrote: ...when he tried...
Note the operative word "tried." I certainly don't claim to know any answer, but I do give most of them a try. As a matter of fact, I spent nearly ten minutes reproducing the question of which you speak, and my suggestion was spot on. While Mark's suggestion was more in with what you were after, that just supports the old adage of there being more than one way to skin a cat.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I have used this code for my project in VC++ MFC(Dialog based application)
goto Tools->Options->select directories tab
select "win32" in "platform" combobox & select "Include files" in "Show Directories for:" Combobox.
suppose VC++ is installed on D: drive
add following directories..
D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE
D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE
D:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE
include "atlbase.h" file also
then use my given function...
Rahul Vaishnav
|
|
|
|
|
Hi all,
Is there a way in MAPI to convert HTML to mime for example
<HTML>
<HEAD>
<TITLE></TITLE>
<STYLE TYPE="text/css">
<!--
.Product
{
font-size:14pt;
font-weight:700;
font-family:arial, sans-serif;
}
.feature
{
font-size:10pt;
font-weight:700;
font-family:arial, sans-serif;
color:#7C5828;
}
.description
{
font-size:10pt;
font-weight:400;
font-family:arial, sans-serif;
}
-->
</STYLE>
</HEAD>
<BODY LINK="#7C5828" ALINK="#7C5828" VLINK="#7C5828">
<TABLE WIDTH=100% CELLPADDING=5 CELLSPACING=0 SUMMARY="">
<TR VALIGN="top" >
<TD ALIGN="center" BGCOLOR="#FAEBA4">
<IMG SRC="1.jpg" ALT="">
</TD>
<TD><ID ID="greeting">Thank you for using Microsoft® Office Outlook® 2003! </ID>
<ID ID="Intro"> This version of Outlook includes new capabilities designed to help you access, prioritize, and act on communications and information so that you may use your time more efficiently and more easily manage the ever-increasing flow of incoming e-mail.</ID><br><br>
<ID ID="Idea">To give you some idea of what is possible with Outlook 2003, we have put together a list of our favorite new features.
</ID><br><br>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
to:
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<meta name=3DGenerator content=3D"Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
a:link, span.MsoHyperlink
{color:#7C5828;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:#7C5828;
text-decoration:underline;}
p.product, li.product, div.product
{mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:14.0pt;
font-family:Arial;
font-weight:bold;}
p.feature, li.feature, div.feature
{mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:10.0pt;
font-family:Arial;
color:#7C5828;
font-weight:bold;}
p.description, li.description, div.description
{mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:10.0pt;
font-family:Arial;}
span.feature1
{font-family:Arial;
color:#7C5828;
font-weight:bold;}
span.description1
{font-family:Arial;
font-weight:normal;}
span.EmailStyle22
{mso-style-type:personal-reply;
font-family:Arial;
color:navy;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body lang=3DEN-US link=3D"#7C5828" vlink=3D"#7C5828" alink=3D"#7C5828">
<div class=3DSection1>
<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'><o:p> </o:p></span></font></p>
<table class=3DMsoNormalTable border=3D0 cellspacing=3D0 cellpadding=3D0 =
width=3D"100%"
style=3D'width:100.0%'>
<tr>
<td valign=3Dtop bgcolor=3D"#FAEBA4" =
style=3D'background:#FAEBA4;padding:3.75pt 3.75pt 3.75pt 3.75pt'>
<p class=3DMsoNormal align=3Dcenter style=3D'text-align:center'><font =
size=3D3
face=3D"Times New Roman"><span style=3D'font-size:12.0pt'><img =
width=3D32
height=3D32 id=3D"_x0000_i1025" =
src=3D"cid:image001.jpg@01C7FC54.44EF62E0"><o:p></o:p></span></font></p>
</td>
<td valign=3Dtop style=3D'padding:3.75pt 3.75pt 3.75pt 3.75pt'>
<p class=3DMsoNormal style=3D'margin-bottom:12.0pt'><span =
class=3Dfeature1><ID ID=3D"greeting"><font
size=3D2 color=3D"#7c5828" face=3DArial><span =
style=3D'font-size:10.0pt'>Thank you
for using Microsoft® Office Outlook® 2003! =
</ID></span></font></span><span
class=3Ddescription1><ID ID=3D"Intro"><font size=3D2 =
face=3DArial><span
style=3D'font-size:10.0pt'>This version of Outlook includes new =
capabilities
designed <span style=3D'font-style:italic'>to help you access, =
prioritize,
and act on communications and information</span> so that you may =
use your
time more efficiently and more easily manage the ever-increasing flow =
of
incoming e-mail.</ID></span></font></span><font size=3D2 =
face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial'><br>
<br>
<span class=3Ddescription1><ID ID=3D"Idea"><font face=3DArial>To give =
you some idea
of what is possible with Outlook 2003, we have put together a list of =
our
favorite new features. =
</font></ID></span></span></font><o:p></o:p></p>
</td>
</tr>
Apologies for the long codes I just want to show a concrete example
Thanks,
Jj
|
|
|
|
|
Hi all. Im trying to make a function to try to attempt something, but when it fails try "one" more time and then move on to the next thing.
So far i've made something that doesnt look close to what i have to do.
<br />
#include <iostream><br />
#include <string><br />
#include <windows.h><br />
using namespace std;<br />
<br />
int main()<br />
{<br />
string test="Testing this";<br />
string test1="Testing the other side";<br />
if(test == test1){<br />
while(test == test1){<br />
Sleep(9000);<br />
cout << "Match " << endl;<br />
}<br />
}<br />
else{<br />
cout << "No match! " << endl;<br />
}<br />
return 0;<br />
}<br />
Any suggestions? Thanx in advance!
|
|
|
|
|
Well the “while” loop will run forever, unless you end the process via the “Windows Task Manager”, because neither string is ever going to change. Of course you do not need to worry about that, because “test” is never going to equal “test1”, so the “while” loop will never run.
I recommend that next time you try to explain what you are attempting to do. The odds are that someone who frequents CP has already tried it.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Try this one -
CString test="Testing this";
CString test1="Testing the other side";
int count = 0;
while (test != test1)
{
Sleep(90);
if (count++ == 10)
break;
}
|
|
|
|
|
dellthinker wrote: Im trying to make a function to try to attempt something...
Such as?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|