Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all 3033 articles
Browse latest View live

Getting IFileDialog to work in VC++ 2005

$
0
0
I'm trying to get at these newer libraries that seem to be available as early as VC++ 2005, like IFileDialog. Unfortunately, even when I #include <Shobjidl.h>, I get told that IFileDialog isn't defined. I assume I don't have it yet. How do I get it?
Does it matter that I'm running WinXP?

[RESOLVED] Trying to create MFC-based automation/COM Dll to be invoked from JScript

$
0
0
Hi everyone:

I should admit, that I do not have much experience working with COM/automation. My goal is to create a C++ module whose methods could be exposed/called by a JScript script running in a .JS file via the Windows Script Host.

In other words, when I call the following from JScript:

Code:

var Obj = new ActiveXObject("ITestComObjMFC.object");
var Result = Obj.Show();

It should invoke my Show() C++ method in the DLL.

So I did some research and found this and this articles.

Now, trying to combine them into my own MFC-based DLL, I did the following:

1. I went into VS 2008 and created a template MFC DLL with support for automation (using the VS wizard.)

2. I then added the code from the second article:
http://www.codeproject.com/Articles/...C-applications
to implement the COM methods.

But the issue is that I'm probably missing something due to my limited knowledge of COM/automation.

My project seems to compile but the linker gives me this error:

Quote:

1>TestComObjMFC32.obj : error LNK2001: unresolved external symbol _IID_ITestComObjMFC
Note that IID_ITestComObjMFC is not defined anywhere in the project directly. It's later added to a TestComObjMFC32_i.c file that is created by the MIDL compiler (if I understand it correctly.)

I tried studying a similar project from the link above which doesn't seem to produce this error but I can't see what's different in my case.

I'll attach my test VS 2008 solution here. (For simplicity, I disabled automatic COM registration is Solution Properties -> Linker -> Register Output.)

Can someone please take a look?

Also, is my implementation of the method described above correct?

PS. I can't reuse the first C-only project, since I need to use MFC in my DLL (my existing libraries are written with it.)
Attached Files

issue in converting a parameter to reference

$
0
0
Hi,

Please forgive me for my basic c++ knowledge.

I tried to change one of the parameters of the c++ function to reference (7th parameter of type BearerQOSInfo) , I am getting the following compile error..This may be minor issue but i have been staring at this for sometime.. I hope c++ gurus give me some quick inputs, and is greatly appreciated.

I just changed the parameter "BearerQOSInfo" to reference type.

But now getting the following error, even after changing the function prototype to reflect this.

ransrc/CPGW.cpp:1158: error: no matching function for call to 'CDiaConnection::SendGxDiaCCOnSession(std::string&, RANType, int, u32&, std::string&, u32&, const BearerQoSInfo&, std::string&)'

The prototype in the header file looks like this:
ransrc/Diameter.h:481: note: candidates are: static void CDiaConnection::SendGxDiaCCOnSession(const std::string&, RANType, u8, u32, std::string&, u32, BearerQoSInfo&, std::string)

Thanks in advance for the quick inputs

~pdk

Change resolution with ChangeDisplaySettings while desktop is extended causes black s

$
0
0
Hi.

I use this function to change resolution:

ChangeResolution(NULL,1440, 900);

bool ChangeResolution(WCHAR *sDeviceName, int iNewW, int iNewH)
{
DEVMODE oDEVMODE = { 0 };
oDEVMODE.dmSize = sizeof(DEVMODE);
EnumDisplaySettings(sDeviceName, ENUM_CURRENT_SETTINGS, &oDEVMODE);

oDEVMODE.dmPelsWidth = iNewW;
oDEVMODE.dmPelsHeight = iNewH;
bool bUpdateReg = true;
LONG lRet = ChangeDisplaySettings(&oDEVMODE, CDS_TEST | CDS_UPDATEREGISTRY);
if (lRet != DISP_CHANGE_SUCCESSFUL)
{
lRet = ChangeDisplaySettings(&oDEVMODE, CDS_TEST);
bUpdateReg = false;
}
if (lRet == DISP_CHANGE_SUCCESSFUL)
lRet = ChangeDisplaySettings(&oDEVMODE, bUpdateReg?CDS_UPDATEREGISTRY : 0);

return lRet == DISP_CHANGE_SUCCESSFUL;
}

This works well.

Problem happens when I desktop is extended (pressing the Windows key + P and choosing "extend"). Then while desktop is extended (to non psychical display), after using my ChangeResolution the screen become black as soon as my function calls ChangeDisplaySettings(&oDEVMODE, bUpdateReg?CDS_UPDATEREGISTRY : 0);

The way to get the screen back is to press Windows Key+P again and then press Enter.

(Since screen is black you do not really see what you do).

It becomes black no matter which new resolution i set.

If I try to change resolution while in extended mode but from Control Panel that is works great so the problem is with my function.

I think this happens since when i change resolution for the default screen (NULL), i also need to change something for the virtual screen - but i am not sure.

If that helps, seems that the screen goes black since for some reason after calling the changeresolution function, display1 is removed and display2 (the virtual screen) is on, but since there is not really physical display2 then i see black screen.

Question is why Display1 is removed when changing resolution?

Any help?

Thanks!

facing problem in MATLAB simple code using fprintf

$
0
0
% This code is displaying the value of B but not printing in a file.
% please help me to solve this problem
write = fopen('tempresults.dat','a');

syms T

B = vpa(int(exp(-(65000.0)/(8.34*T)),273.15,573.15))

fprintf(write,'%e',B);

Link Time Symbol undefined Error when exporting a DLL method wrapped in a namespace

$
0
0
I got a method which is defined in a .cc file and has the following syntax

Code:

namespace Sim
{
        #define DLL __declspec(dllexport)

        class DLL Scheduler
        {
            void ActivateAt    (double AtTime = CurrentTime(), Boolean prior = FALSE);
        };
};
           


namespace Sim
{
        void Process::ActivateAt (double AtTime, Boolean prior)
        {
                // No op if already scheduled
                if ((AtTime < Process::CurrentTime()) || Terminated || !idle()) return;

                Passivated = FALSE;
                wakeuptime = AtTime;

                ReadyQueue.Insert(*this, prior);
        }
};

When importing back into the main exe like this
Code:

namespace Sim
{
        #define DLL __declspec(dllimport)

        class DLL Process : public Thread
        {
              void ActivateAt    (double AtTime = CurrentTime(), Boolean prior = FALSE);
        };
};

I receive the following error
Code:

Error        1        error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall Sim::Process::ActivateAt(double,unsigned short)" (__imp_?ActivateAt@Process@Sim@@QAEXNG@Z) referenced in function "public: virtual void __thiscall Sim::Arrive_Mt::Body(void)" (?Body@Arrive_Mt@Sim@@UAEXXZ)        E:\Jacky\Documents\Visual Studio 2013\Projects\Perfectsim\Perfectsim\Perfectsim\CMyApp.obj        Perfectsim
Any ideas why this would happen?
Thanks
Jack

Word break in a richedit box

$
0
0
Visual Studio 2013 Community Edition on windows 7 Ultimate.
Dialog app with two rich edit boxes. The boxes are set to auto vertical scroll true, horizontal auto scroll false.
I am attempting to read from one rich edit box one line at a time and print these lines out to the second rich edit box, one line at a time.
I am using the following code to read the line:
Code:

CString Line1;
int nLineLength = 0;

nLineLength = m_RichEditVar.LineLength(1);
m_RichEditVar.GetLine(1, Line1.GetBufferSetLength(nLineLength + 1), nLineLength);

The problem is that LineLength() includes some word wrap characters that are put into the text when it is typed into the first rich edit box. When this line is printed out in the second box, these characters show up. The characters are '\uCDCD' and I tried to use CString::Find to trim the line length that way but Find couldn't locate the characters.

Anyone have any idea how to read or print the line without showing these characters?

printer spool app

$
0
0
hi everybody!
Can you help me with a simple app? i want an app that will interact between the print button and the spool. for instance i want to print a .docx, i hit the print button and i want a pop-up that will tell me the following:
you will print 3 pages
duplex: yes/no
color/black&white

to continue enter password
_____________________
|_____________________|

and if the password is right then sent the file to the spool service and print it

please help me!!!

Column autosizing in the ListView

$
0
0
Hi, ALL,
The ListView has the possibility to autosize the column based on the content of it with the "LVSCW_AUTOSIZE" flag.
However the "Header Control" that is used by ListCtrl/ListView does not have such flag. Therefore if the list control/view is empty, double click on the column divider will not autosize the column.

Is it possible to autosize the "Header Control" column in an empty ListCtrl/ListView?

Thank you.

I'm using pure WinAPI if it matters.

Thank you.

On click tab event

MFC PrintWindow() only works sometimes

$
0
0
Hi, I want to make a Screenshot of a CWnd and then Print it out. I already created some basic Code for testing purposes but if I'm actually printing it only works sometimes (on some Printers in combination with some PC's I'm printing from). What's always working is to directly draw a Rectangle to the Device Context but when I'm calling the "printWindow" It sometimes has no effect (it always returns true). I also don't think that its a driver problem of the PC because I never had any problems and I also tested it on 2 more Pc's.

So there Are 2 Scenarios when I'm printing:
1) I only see a Rectangle (white/transparent inside)
2) I see the Window and a Rectangle around it

In my Example I created a Basic MFC App (DialogBased) and just added a Button to Print the Window. I also created another Function to get the Default Printer Name but I dont think thats the cause so I din't uploaded it here.

Here is the Code:

Code:

//Create Members
CDC pDC;
HDC hdc;
 
//Get Printer/Printer Settings
LPCSTR buffer = NULL;
GetDefaultPrinterName(buffer);
hdc = CreateDC(_T( "winspool" ), buffer, NULL, NULL);
pDC.Attach(hdc);
 
//Start Document Printing
pDC.StartDoc("test");
pDC.StartPage();
 
if (! ::PrintWindow(this->GetSafeHwnd(), pDC.GetSafeHdc(), PW_CLIENTONLY))
    AfxMessageBox("Error when calling \"PrintWindow()\"");
 
//Render Frame Rectangle
CRect WindowRect;
GetClientRect(WindowRect);
WindowRect.MoveToXY(0,0);
CBrush brush;
brush.CreateSolidBrush(RGB(0,0,0));
pDC.FrameRect(WindowRect,  &brush);
 
// Finish Printing
pDC.EndPage();
pDC.EndDoc();


Do you know what causes the problem or what could I do as an Workaround?

cricheditctrl cfe_hidden

$
0
0
When I set a set of chars as hidden (cfe_hidden), with SetSelectionFormat, there is a problem. If I set, for example, chars 5-10 as hidden, if I do a GetSelectionCharFormat on char 5-10, I see that CFE_HIDDEN is set. But if I look at those chars one by one, via a loop on this range - and SetSel on each char one at a time - it does not show that CFE_HIDDEN is set. It also does not show me the char value when I do GetSelText on that one char either.

Is there something else I need to set or look at - when I look at it char by char. If I set the CFE_LINK, for example and do the same - it is fine!!

In which case how can I determine which stretch of chars are hidden?

Help??

Thanks

Sharon

Test RS232

$
0
0
Hi,
I need to test the RS232 side of a protocol/format convertor (Ethernet/UDP to RS232 -serial 9600, 8bits, Parity none, 1 stop bit-).
I have looked at the CodeBlocks compiler to write a simple console program myself. It will take a while before I know how to use it.
I someone willing to write a simple executable file for Windows XP.

The program has to receive 13 bytes over RS232 and send the same 13 bytes with a delay of about 0.2 seconds (in a byte array) over RS232 back again (needed for a software handshake). Communicating over Serial Port 2. Would be nice to see the received 13 HEX bytes on screen to check the incoming bytes.

For someone with a lot of C++ compiler experience it has to be easy. I know I have to write it myself but it takes to much time to learn the compiler.

thanks,

Henk

[RESOLVED] CFileDialog Initial Directory - Reg

$
0
0
Hi,

i have 2 browse button. one for getting the filepath and another for getting the folderpath.
If i was allocate different type of initial directory at application starting time.
Its open the default directory correctly.

if i get the filepath at first time, then like to get the folderpath, the default folderpath goes to filepath location.[ex: filepath = "E:\OP\1.csv" and folderpath = "D:\\".]

help me.

Code:

//Default Path initialized
CString folderpath = "D:\\";
CString filepath  = "E:\\";
void CTestDlg::OnBnClickedFolderpath()
{       
        folderpath = GetFolderpath(folderpath);
        ::AfxMessageBox(folderpath);
}

void CTestDlg::OnBnClickedFilepath()
{       
        filepath = GetFilepath(filepath);
        ::AfxMessageBox(filepath);
}

CString CTestDlg::GetFolderpath(CString fldp)
{
        CFolderPickerDialog fileDlg;
        fileDlg.m_pOFN->lpstrInitialDir = fldp;       
        //::AfxMessageBox("Initialized fldp = "  + fldp);

        if(fileDlg.DoModal() == IDOK)
        {       
                fldp = fileDlg.GetFolderPath();
                ::AfxMessageBox(fldp);
        }
        return fldp;
}

CString CTestDlg::GetFilepath(CString fp)
{
        CFileException CfileEx;       
        TCHAR szFilters[]= _T("csv File (*.csv)"); 
        CFileDialog fileDlg(TRUE, _T("csv"),  _T("*.csv"), OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters);   
    fileDlg.m_ofn.lpstrTitle = _T("Open CSV File");
 
    fileDlg.m_pOFN->lpstrInitialDir = fp;       
        ::AfxMessageBox("Initialized filepath = "  + fp);
 
  if(fileDlg.DoModal() == IDOK)
  {                         
          fp = fileDlg.GetPathName();
          ::AfxMessageBox(fp);
  }
  return fp;
}

Graph

$
0
0
Hi,

I have an array of data. Using MSChart control, the array of data plotted successfully.
I like to plot vertical lines in the same graph. Is possible ?

If not, which graph suitable for my requirement. Find the sample requirement.
Attached Images
 

windbg Windows 7 64-Bit / Visual Studio 2010 Ultimate

$
0
0
Can somebody weigh in here and tell me if they have experienced this?

Also please tell me what exactly they experience with VS2010 Ultimate
and Windbg.

I have a laptop I am supposed to be using to debug crash dumps.

windbg is not acting correctly. I decided to do a test and tried to just
debug a program, and although I can set a breakpoint, the debugger
does not stop on the breakpoint.

I know there is a problem with the Visual Studio 2010 runtime libraries and
windbg x64 / Windows SDK on Windows 7. The developer who gave me the
laptop said the development environment and windbg were installed correctly.

I doubt it.

Please give me a frame of reference here.

Thanks!

Installer prerequisites problem

$
0
0
Hello

Either on ClickOnce or Visual Studio Installer I use "DotNetFX45" and "SQLLocalDB2014 (x86 & x64)" as prerequisites. All these files are included inside the SETUP folder (Hence, no internet connection is requiered by end-user).

The problem comes because SETUP always tries to install SQLLocalDB whether is already installed on PC or not.

So, when it starts to install SQLLocalDB an error shows up like this: "This software is already installed on PC. Install abort"... Installer ends and not continue with my App install proccess.

I thought the installer should verify if prerequisites are already installed on PC in order to ask to end-user to install it. And whatever happens then proceed to install my App.

Is there any way to fix it?

How to let user to choose what prerequisite install or even better, how to set SETUP be able to verify what prerequisite is needed?

Thanks.

Visual studio problems

$
0
0
VS 2010

How can I disable Error list Window to open every time when I debug in Visual Studio? I have the errors in Output window and that is OK but another panel is displayed which takes the screen place and I need t disable this.

Help for Create a ANE

$
0
0
Hi all
I'm a flash developer. In flash (air technology) we can use c++ native code for extends our API before adobe do this.
This tutorial show everything:
http://easynativeextensions.com/wind...e-dll-project/

So we have two section: c++ and as3.
Now I want a ANE (Air Native Extension) for all hardware info: All information provided by Win32.

Can anyone to help me for create c++ section of this ANE?

How to make button stay down in winapi?

$
0
0
Edit: Wrong title of the question

How to enable checkbox or disable? I know that it has some enable bit but how to do it?
Viewing all 3033 articles
Browse latest View live