|
Hi.
I am in a project that needs to use a serial port to virtually set so that it acts as a virtual serial port for interfacing with many devices. In The market, there is software on it but that cost US$100++ per port which is too costly for my school project.
I seen codes in Windows CE using RegisterDevice but when i use in Visual C++ on desktop, it says undeclared even if i include <windows.h> and <winbase.h>
Any help will be greatlt appreciated.
Thank You
|
|
|
|
|
Hi,
I've recently converted some C code into C++ but am now having problems with some of the memory allocation/deletion in it. The problem Im having is taht when I come to delete a float** I get an invalid heap error. I think I *may* be deleting the wrong bit of memory (not used pointers to pointers before). I've pasted the code fragment below and also the last few bits of the call stack where it crashes.
Can anyone spot what I'm doing wrong and also how I can fix it!
cheers,
void CTestprogDlg::OnButton1()
{
float **xMeas ;
// TODO: Add your control notification handler code here
xMeas = OpenMatrix ( 0,
1,
0,
0 ) ;
xMeas [0][0] = 1 ;
CloseMatrix ( xMeas,
0,
1,
0,
0 ) ;
}
float**
CTestprogDlg::
OpenMatrix ( long int nrl,
long int nrh,
long int ncl,
long int nch )
//allocate a float matrix with subscript range m[nrl..nrh][ncl..nch]
{
long int i ;
long int nrow = nrh - nrl + 1 ;
long int ncol = nch - ncl + 1 ;
float **m ;
/* allocate pointers to rows */
//m = (float **) malloc ( (size_t) ( ( nrow + NR_END ) * sizeof ( float*) ) ) ;
// TBD - changed to new instead of malloc
m = new float* [ nrow + NR_END ] ;
if ( !m )
{
AfxMessageBox ( "Matrix Allocation Error!!\n" ) ;
exit ( 1 ) ;
}
m += NR_END ;
m -= nrl ;
/* allocate rows and set pointers to them */
//m[nrl] = (float*) malloc ( (size_t) ( ( nrow * ncol + NR_END ) * sizeof ( float ) ) ) ;
// TBD - changed to new instead of malloc
m [nrl] = new float [ nrow * ncol + NR_END ] ;
if ( !m [nrl] )
{
AfxMessageBox ( "Matrix Allocation Error 2!!\n" ) ;
exit ( 1 ) ;
}
m [nrl] += NR_END ;
m [nrl] -= ncl ;
for ( i = nrl + 1 ; i <= nrh ; i++ )
{
m [i] = m [i - 1] + ncol ;
}
return ( m ) ;
}
void
CTestprogDlg::
CloseMatrix ( float **m,
long int nrl,
long int nrh,
long int ncl,
long int nch )
//free a float matrix opened with OpenMatrix
{
//free ( (char*) ( m [nrl] + ncl - NR_END ) ) ;
//free ( (char*) ( m + nrl - NR_END ) ) ;
// TBD - check that we want to delete all of v
// also check that this is deleting all of the object as it is a float**
long int nrow = nrh - nrl + 1 + NR_END ;
for ( int d1 = 0 ; d1 < nrow ; d1++ )
{
delete [] m [d1] ;
}
delete [] m ;
}
NTDLL! 77f9f9df()
NTDLL! 77fb4966()
NTDLL! 77f8b3d2()
KERNEL32! 77e944cd()
_CrtIsValidHeapPointer(const void * 0x011e766c) line 1697
_free_dbg_lk(void * 0x011e766c, int 1) line 1044 + 9 bytes
_free_dbg(void * 0x011e766c, int 1) line 1001 + 13 bytes
operator delete(void * 0x011e766c) line 351 + 12 bytes
CTestprogDlg::CloseMatrix(float * * 0x011e7624, long 0, long 1, long 0, long 0) line 176 + 21 bytes
|
|
|
|
|
When you allocate memory using new, you are returned a pointer which is used as a reference in the delete call. In your allocation where you do
m = new flot*[size];
following this you do
m += NR_END
etc
This modifies you pointer address. You need to call delete on the same pointer that was given you by the new call.
As you are working with matrices, why not make use of a matrix class such as this one: Matrix class[^]
which handles automatic allocation and clean up and gives you access to all the regular operators for standard types too.
If you vote me down, my score will only get lower
|
|
|
|
|
cheers Roger, I hadn't noticed that they where changing the pointer!
|
|
|
|
|
Hai,
TCHAR szFileName [] = _T("D:\\NEW Images VC++\\IDB_BITMAP.bmp");
HBITMAP hBitmap = (HBITMAP)LoadImage( NULL,szFileName, 0, 0,SS_BITMAP,LR_DEFAULTSIZE | LR_LOADFROMFILE );
if(!hBitmap)
{
AfxMessageBox(_T("failed"));
}
m_CtrlPicture.SetBitmap(hBitmap);
LR_DEFAULTSIZE and LR_LOADFROMFILE are not supported in WinCE. Is there any other functions to load the bitmap.
Give your hands
|
|
|
|
|
Hello!
I need to set the background color of all the controls on a dialog.
I have problems with a tab control.
Does someone know how to do it?
-Alma-
|
|
|
|
|
i'm using visual c++6.0 to initialize the parallel port
i try to use the command of _outp and _inp so as to write and read the signal but i can't success
then i use inline aassembler to do it but it has errors again. i have tried for many times but i still can't success.
i think the main problem are in the lines below,
_asm out dx,al
_asm in al,dx
would anyone can help me?
the programme is as follows,
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
#define PortAddress 0x378
short PortOut(unsigned int portadr,unsigned char data)
{
_asm mov edx, portadr
_asm mov al, data
_asm out dx,al //Loaded 'C:\WINNT\system32\ntdll.dll', no matching symbolic information found.
return(portadr,data);
}
unsigned char PortIn(unsigned int portadr)
{
unsigned char data;
_asm mov edx,portadr
_asm in al,dx
_asm mov data,al
return data;
}
int main(void)
{
short Dummy;
short PortData=0;
int pd=0;
cout<<"Input portdata\n";
cin>>pd;
Dummy=PortOut(PortAddress,pd);
PortData=PortIn(PortAddress);
cout<<"data at"<
|
|
|
|
|
You're on the right lines with _inp() and _outp() but if you are using an "NT-based" OS (Win NT, 2000 or XP) you have to use a special driver to bypass the port security - by default you cannot directly access I/O ports.
There are a number of drivers available that do the same thing. UserPort is as good as any: http://www.embeddedtronics.com/public/Electronics/minidaq/userport/UserPort.zip
Hope that helps
|
|
|
|
|
You can't do it using _inp and _outp , or even in assembler. Windows won't let you. You'll have to use the Windows functions for accessing parallel ports - look at CreateFile() .
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi All,
I want to use a COM dll.
So I am first calling CoInitialize();
Then #import "Dll path" no_namespace
Then I am declaring the required inteface pointer and then calling CoCreateInstance();
But the compiler give me an error saying the interface is undelcared. But it generates the .tlh and .tli files in my debug directory of the project. And I think .tlh file conatains all definations. So ow what is wrong in my approach?
Do I need any .h file also in addition to .dll.
Please reply early.
--------------
Vaibhav...
|
|
|
|
|
Add the attribute "named_guids" to your #import directive.
Otherwise identifiers for interfaces and CLSID such as "IMyInterface" are undefined.
--
Roger
|
|
|
|
|
Roger,
I did that...
#import "D:\Firewall Settings\IMP Files\hnetcfg.dll" no_namespace named_guids
still getting the same error..
--------------
Vaibhav...
|
|
|
|
|
Five alternatives:
1. Verify that you are using IID_IMyInterface in the call to CoCreateInstance, or
2. you are using __uuidof( IMyInterface ) in the call to CoCreateInstance.
3. Check your spelling.
4. Search the .tlh file for the identifier that is undeclared and verify that it exists.
5. Do the import in stdafx.h to make the identifiers "globally" declared.
If this doesn't help I suggest you post some code showing how you are calling CoCreateInstance and the declarations of the identifiers you are trying to use from your imported library, i.e. snippets of the .tlh file.
--
Roger
|
|
|
|
|
Hi Roger,
First of all sorry to reply late. I was very busy in a project.
Well, when I compile with #import "Dll path".. it creates a .tli and .tlh file in my debug directory. I checked those files by opening them in VS. None of them defines INetFwProfile interface. But I want to make use of INetFwProfile which as per microsoft is in the hnetcfg.dll which I am using with #import.
As far as code is concern it goes like this..
////////////////////////////////////////////////////////////////////// HRESULT hr = S_OK;
// Initialize COM.
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = S_OK;
fwComInitialized = TRUE;
}
else
{
printf("CoInitialize failed: 0x%08lx\n", hr);
goto error;
}
INetFwProfile* fwProfile = NULL;
//////////////////////////////////////////////////////////////////////
Here I have not written Cocreateinstance() yet. Before that only its not complinig and last line give errors as mentioned below.
error C2065: 'INetFwProfile' : undeclared identifier
error C2065: 'fwProfile' : undeclared identifier
error C2106: '=' : left operand must be l-value
Does it mean hnetcfg.dll does not contain INetFwProfile. As far I know .dll contains only implementation and when you compile .tlh gets created with contains the declaration of the interface.
Do I have to include any .h also or have to give path of any other file in Include directories from Options in VC++ 6 compiler. I dont thinks so...
--------------
Vaibhav...
|
|
|
|
|
Well...
The errors are expected since the interface is not declared.
I've tried to import hnetcfg.dll but there is no interface called INetFwProfile in my library either.
I browsed MSDN at the net and found the following link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ics/ics/inetfwprofile.asp[^]
The article tells me that WinXP SP2 is required, do you have it?
Furthermore the article says that the interface is declared in a header file called netfw.h, which I presume is shipped with VC7 which I don't have. I'm running VC6 and I can't find that header file.
The article doesn't say anything about hnetcfg.dll. Where did you get the information that the interface could be found in this library?
The bottom line is that you are looking for the interface in the wrong place. Or maybe you're looking at the right place but the library is an older version that doesn't contain the interface you're after.
Either way I cannot help you since I cannot find any information that confirms any of this.
--
Roger
|
|
|
|
|
Roger,
Things are crystle clear now..
Go though this link http://blogs.tonygoodhew.com/xpsp2/archive/2004/05/19/269.aspx
In the third paragraph of this article it is said that either you can use dll by importing it or create .h and .tlb files using midl.exe. I prefered the formal over later. But the dll is not availbale with this PSDK. So I took the dll form a machine whre XP SP2 was installed.
But now I got the concept. That dll is just contains the core objects required to manipulate the firewall. But one requires Firewall manager also (which I thought would be in that dll only) which deals with that dll objects. Now this manager is defined in netfw.h. So later I went for the second approach and created netfw.h file from netfw.idl using midl.exe and used it in my project. Its working fine now.
As you said it required XP SP2. Ya but that is only for the client machine. i.e. the taget of the software must be a XP SP2. The developement machine could be any thing on which you have installed PSDK. I had already used the link you gave me for the reference in my project since that is only source for reference.
So the bottom line is either I couldn't get the exact meaning of the 3rd paragraph of the link I mentioned above or that link does not explain well.
Anyway, thank you for taking interest in my problem.
Have a nice day!
--------------
Vaibhav...
|
|
|
|
|
Vaibhav Sanghavi wrote:
Then #import "Dll path" no_namespace
Then I am declaring the required inteface pointer and then calling CoCreateInstance();
I'm curious to know why you are using #import but not making use of the generated Smart Pointer interface.
I find it easier to use the smart pointers.
e.g
<br />
#import "craxdrt.tlb" no_namespace named_guids <br />
<br />
<br />
IApplicationPtr m_Application;<br />
<br />
HRESULT hr = m_Application.CreateInstance(__uuidof(Application));<br />
<br />
m_Application->OpenReport(reportName);<br />
<br />
Michael
CP Blog [^]
|
|
|
|
|
Hi,
I'm using MSHFlexgrid and I need to use a "custom" autoresize.
* if the text is to long to fit in the cell cut off the text and put "partoftext..." in the cell. if the user clicks on the cell he will, off course, see the whole cell.
My first idea was to get the width of the cell (OK) and the width of the text (GetCellFontWidth() ?) and then work from there (I do keep in mind that one is in twips and the other in points)
problem is that m_flexArray.GetCellFontWidth(); always returns 0.00000
m_flexArray.GetCellFontSize(); does returns a value, but in cases of Times New Roman and stuff it doesn't do me any good does it?
can anybody give me any clues on how to solve this?
(yes, it's not really an autoresize )
tnx for your help!!
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
class A
{
public:
virtual fun();
}
class B:A
{
public:
fun();
}
main()
{
B b;
b.fun();// this will call class B's function.
//But i want to call function fun() of class A with the same object ( of B).
//any way ??
}
|
|
|
|
|
xcavin wrote:
any way ??
Yep.
b.A::fun();
That should successfully call the base function.
Happy Programming and may God Bless!
"Your coding practices might be buggy, but your code is always right."
Internet::WWW::CodeProject::bneacetp
|
|
|
|
|
Hi
You can typecast the object of B to A and call the function
So just change the last line of your code to
((A)b).fun(); // this will call class A's function.
--------------
Vaibhav...
|
|
|
|
|
i wish to make some registry entry at the time of installing my software and use the entries later in my sofware..
should i make the entries in HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE? basically, i want to know which is the appropriate path.
ask_you
|
|
|
|
|
It depends. If you want all users of that machine to be able to use you software then you need to saved it on HKEY_LOCAL_MACHINE. But if for currently logon user only, then save it to HKEY_CURRENT_USER.
|
|
|
|
|
|
Could you please help me on this one... I have to Read Cookies along with the Contents. How will I be able to do that?! What Class/Methods are Involve?! Thanks in Advance!!!
|
|
|
|