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

Procedure to Compare 2 Strings with the following criteria

$
0
0
Procedure to Compare 2 Strings with the following criteria

Hi everyone - I hope your day is going great.

Can someone please kindly help me with the coding of the following function -
I have absolutely no clue where to start -

Given the following sets of numbers -
1154 1179 2154 2554 2484 2144 4515 1144 1517 4815 1481

Given the Index number of 1154

I want to search the numbers for the Index number of 1154

The search will return a True if I can find 3 or 4 same digits between the Index number and the 8 numbers

The search also have the following criteria -

meaning that -

1154 when compared to 1154 == true
1154 when compared to 1179 == false
1154 when compared to 2154 == true
1154 when compared to 2554 == false
1154 when compared to 2484 == false
1154 when compared to 2144 == false
1154 when compared to 4515 == true
1154 when compared to 1144 == true
1154 when compared to 1517 == true
1154 when compared to 4815 == true
1154 when compared to 1481 == true

the index number can also be of type - 1234, 1123, 1112, 1111

:)

Thank You

LNK1120 error - VS2012 project using a VS2010 DLL

$
0
0
I have a third party DLL compiled with vc10 (VS2010).
It exports the following function
:

Code:

bool myDLL_EXPORTS_API myFunction(std::vector<int>::const_iterator c)
{
        return true;
}


My exe uses this DLL. I am trying to compile my exe with vc11 (vs2012).
Code:

#include "stdafx.h"
#include <vector>
#include "myDll_VC10\myDll_VC10.h"

int _tmain(int argc, _TCHAR* argv[])
{
        std::vector<int>::const_iterator c;
        myFunction(c);

        return 0;       
}

I get the following linker error:
1>usingDLLvc10.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) bool __cdecl myFunction(class std::_Vector_const_iterator<class std::_Vector_val<struct std::_Simple_types<int> > >)" (__imp_?myFunction@@YA_NV?$_Vector_const_iterator@V?$_Vector_val@U?$_Simple_types@H@std@@@std@@@std@@@Z) referenced in function _wmain
1>C:\Work\Training\vectorReproduceBug\usingDLLvc10\Debug\usingDLLvc10.exe : fatal error LNK1120: 1 unresolved externals



Note: This code compiles and links if my exe is compiled with vc10 (VS2010).

How do I fix this linker error without the third party library compiled with vc11 (VS2012)?

CString replace? index of?

$
0
0
Is there a function that can take out part of the string such as,


C:/Users

I want to take out Users.

I need the function to search for the first "/" and take out the last dir name

C:/windows would be c:
C:/users/bla would be c/users

Im programming in visual studio 6.0 MFC

File association with Excel problem

$
0
0
Hi,
in my application i can a export Data as an Excel-XML File, but first i need to check:
-Is Excel installed, and get a path for it
-make File association *XML-File with Excel

My try:
i use a Funktion MsiLocateComponent(...) to check if Excel is there, this works, but there is an problem, if someone has a newer version of Excel after i finish my application??
That means my solution is to static, if i check only for a registry key like "{0638C49D-BB8B-4CD1-B191-052E8F325736}" <<--- this is for Excel 2007,
and this is for Excel 2010 {538F6C89-2AD5-4006-8154-C6670774E980},but if there is an "Office-Excel 2015" with unknown Registrykey after i'm finish my work, they dont find a Excel .... :(
Does anyone have an idea if there is an better way to check if is Excel installed and where is the path to Application?

Next step is to check if is XML file associated with Excel?
Sorry i don't have an idea how to check this ...

Thanks for any help
break

ADO Connection problem in C++ Builder

$
0
0
Hi my friends.I try to connect my application in C++ builder 6 from my home pc by ADOConnection string, to a database in MSSQL Server installed on my work pc that has a static IP(Public IP). I already open a UDP 1433 port on both routers (home & work)and i have apply an exception in both firewalls for SQL server and C++ application respectively...but i can't connect to database. Does anybody know the complete procedure step by step for the connection please ?

Problem accessing user directory in Win 7 Pro

$
0
0
I have been using the code below to extract the current user directory in order to read and write to certain files, presumeably independent of whether or not the user has administrative privileges. This has been necessitated in Win 7 because applications installed in the customary C:/Program Files(x86)/ are not allowed full access to files in the installed app root directory. This was working just fine until just this week when suddenly, for the first time, I found that the user directory retrieved was different when the app was run without administrative privileges in 'Start without debugging' configuration, both in Debug and Release configuration. Note that I have tested the identical app on Win2K and Vista and in neither case is it a problem on those OS machines. More mysterious is the fact that this ONLY happens on Win7 (VS2010 Ultimate) when run in the IDE. Run from the windows explorer double click, the app runs just fine in release and debug mode and monitoring the debug version using DbgView indicates that the expected 'Roaming' User directory is retrieved.

For example:
- without debugging (both Debug and Release configuration) the code below produces:
Quote:

m_csUserDirectory =: C:\Users\MPLIAM\AppData\Local\PliaTech\UeberKrypt
- with debugging (both Debug and Release configuration) the code below produces:
Quote:

m_csUserDirectory =: C:\Users\MPLIAM\AppData\Roaming\PliaTech\UeberKrypt
Either this has been the situation from the outset and I just never noticed it (hard to imagine as I've been on this project for 6 months with 50+ builds), a recent Windows update has changed things, a bug, or I'm just plain stupid (not hard to imagine at all).

From a practical standpoint, if this is the way things are to be, my installer will need to install necessary files in both user directories and the app will need to access both depending upon user privileges.

Any ideas greatly appreciated.

Code:

/// This routine retrieves the process's environment block
/// using GetEnvironmentStrings, parses that block pointed to
/// by the generic international text pointer LPTCH, and returns
/// the requested string lpszVarStr as a string.
/// Note that the block lpvEnv environment variable substrings
/// are separated by NULL byte, and the block is terminated by a NULL byte.
/// The header files <windows.h>, <tchar.h>, <stdio.h>, <string>, and
/// <iostream> need to be included.
/// http://msdn.microsoft.com/en-us/library/windows/desktop/ms683187(v=vs.85).aspx
/// http://msdn.microsoft.com/en-us/library/windows/desktop/ms682009(v=vs.85).aspx  //code fr example 3 here
CString CMyApp::GetEnvVar(wstring wsEnVar)
{
    // Get a pointer to the environment block.
        LPTCH lpvEnv = GetEnvironmentStrings();
    LPTSTR lpszVarStr = (LPTSTR) lpvEnv;

    // If the returned pointer is NULL, exit.
    if (lpvEnv == NULL) return _T("GetEnvironmentStrings failed (%d)\n");

        int n = -1;
        wstring wstr = _T("");
        CString cstr = _T("");
    while (*lpszVarStr)
    {
                wstr = wstring(lpszVarStr);
                n = wstr.find(wsEnVar);
                if(n >= 0) break;
        lpszVarStr += lstrlen(lpszVarStr) + 1;
    }
 
        FreeEnvironmentStrings(lpvEnv);

        n = wstr.find(_T("="));
        wstr = wstr.substr(n+1, wstr.size()-n);

        cstr = wstr.c_str();

        return cstr;

}// GetEnvVar(string wsEnVar)

Kitchens In Gillingham

CListCtrl Multiple selections

$
0
0
hello


How do you select multiple folders and upload them. Search recursively? I cant find any code or examples.

Repaint on CDockablePane Resizing

$
0
0
I have a tabbed CDockablePane with 3 Panes in total lets say Pane1 is main pain and Pane2 and Pane3 are added to the Main pain with AttachToTabWnd. In each pain I have 1 control but I will also eventually add a toolbar as well. I have created a CListCtrl with each pane. I call Override OnSize to resize the ListCtrl when the pane resizes. Problem is when I resize the width (enlarge) it does not update. If I drag the right border 1 pixel to the left it does update correctly. I have tried invalidating the pane after resize but still does not update as it should. What can I do to remedy this?

Cacheing MFC menues

$
0
0
I have an VS 2010 VC++ project. I have changed a few things in the .rc file but the changes are not appearing when I debug the program. I have taken the .exe to another computer and the changes appear. Is there something that caches the resources? There are no errors when I compile or debug the program. I have tried "build clean", "rebuild" and "build solution". I have also tried to remove the whole debug directory. I have looked at the .res file in the debug directory and it has the changes.

Can I Study C++ to Learn C?

$
0
0
I have to know C for a non-programming job interview--not expert level, but enough to look at code and know what's going on. I've studied C++ but it's been a while and I'm rusty, so I need to study. The problem is, all the books I really like are for C++; there are very few for C alone.

Would I be okay studying C++ books and just avoiding the OOP-related parts (classes, objects, inheritance, polymorphism, encapsulation, <iostream> vs. <stdio.h>)? Or are there too many other major or minor differences that will screw me up on my C test? Any other significant differences to avoid?

loop error in c++

$
0
0
i ,

I am trying to create a loop to call in the entries from the text file named Set.
The entries of Set.txtare :
1 2 3
2 4 5
and so on .. (64 such combinations)[/CODE]

it basically means the first combination for testing is 1 2 3 and next has to be 2 4 5 and so i have 64 such entries defined in set

my test files are located in D://data// and are named tst_data1 to tst_data64.


i created a loop for test set but its incorrect

Code:
// loop for test samples
char basefilename[] = "D://data//";
char , testFilen[160], numiChar[10];

for (int i=1; i<=64; i++) {
strcpy(basefilenme, "D://data//");
strcat(testfilename, Set[]);


if (testfilenme[i]=='_' && testfilenme[i+1]=='\0'){
strcat(testfilename, numiChar);
strcat(testfilename, "_");
break;
}

strcat(testfilename, ".txt");
cout<<testfilename<<endl;

please correct me how can i call the Set .txt and how to define it.

thanks

UnixTimestamp to time

$
0
0
I have the following code that takes a unix time stamp into a date.

Code:

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
//e.g. 1331812987 = Thu 15 Mar 2012 01:03:07 PM CET
int main(int argc, char** argv) {
 struct tm * dt;
 char b[19];
 long ts;
 
 ts = 1331812987;

 
 dt = localtime(&ts);
 // use any strftime format spec here
 strftime(b, sizeof(b), "%c", dt);
 fprintf(stdout, "%s", b);
 getch();
 return 0;
}

Everything is right accept the HOUR of the timestamp which is 07 instead of 01

is this fixable?

selecting from a group in c++

$
0
0
Hi,

I have N vectors which look like this:
[1→m] [m+1→2m] [2m+1→3m] [3m+1→4m] [4m+1→5m]..... [{(N-1)m}+1→Nm]

I want to select 1 element from each vector without duplication of any combinations.
Essentially only when all combinations are done with 1st element in first vector ,only then it should move to next element in first vector
say i have elements :[123] [456] [789]

my combinations should be like
147
148
149
157
158
159
167
168
169
247….

Also, i cant have any repetitions and only after all combinations of 1 are done only then the loop has to move to next combination ie 247 combination and so on.

i tried NCK (n choose k) command but it gave me random combinations.
how should i go about it with using minimal for loops?
thanks!

Understanding Synchronization in detail in MFC.?

$
0
0
Hi,

I want to understand synchronization objects in MFC in detail.
if anybody know about any good book / tutorial, please send me the link for the same.

I want to understand Mutex / Semaphores / Events / Critical Section in detail....How to use implement and use in practical examples.





Regards,
Mbatra

Migration of Print Preview code from VC++ 6.0 to VC++ 2008

$
0
0
Hi,
I am migrating my project from VC++ 6.0 to VC++ 2008.I have been successful in doing so until now,where I am stuck up with Priint Preview part of the project.I have googled for this, and made some changes to my code.I find no compilation errors in the code,but The Print Preview editor doesn't launches itself.
I found that,making

CPrintDocument::IsPrintPreview_S()

forcefully false in the code while running,launches the Print Preview editor after some assertions.It launches with inaccuracies in the display.i.e., Scrollbar is not moving properly and others.

As I said before,I have made these following code changes,

CWnd* pMainWnd = GetParentFrame();
if (DYNAMIC_DOWNCAST(CFrameWnd, pMainWnd) == NULL)
{
// if it's not a frame, we'll try the main window
pMainWnd = AfxGetMainWnd();
}

CFrameWnd* pParent = STATIC_DOWNCAST(CFrameWnd, pMainWnd);

CWnd* pToolBar = pParent->GetDlgItem(AFX_IDW_PREVIEW_BAR);

Thanks to anyone who helps me in this.:thumb:

Numerous problems when application is started using "Open with"

$
0
0
When the file that my application saves is opened using right-click/Open with, there are many mysterious problems:

1) AfxMessageBox will not work (based on a small sample) from anywhere in the program. It is ignored.

2) Any files written to temp directory or to the working directory (directory of the opened file) can't be saved because the file path has been mysteriously changed to c:\windows\system32.

3) Any reference to the directory of the opened file is changed to c:\windows\system32.

At first I thought this was a Windows security measure but it seems too crazy.

The program is 13 years old and works fine when the file is opened from inside the program using File > Open or is double-clicked on.

This recent behavior either started when I upgraded from Visual C++ 6.0 to Visual Studio 2008 or started using Windows 7.

Any ideas will be must appreciated.

Have you build a Windows Phone 8 or Windows 8 app yet?

$
0
0
Have you build a Windows Phone 8 or Windows 8 app yet? We are considering a program on the site that would promote (at a minimum list) apps built by our members (you). I'm wondering if there are a few such apps yet. If you've built an app, can you respond in this thread with the name of the app(s) and whether each is targeting Windows Phone 8, WP 7.8, or Windows 8?

Thanks!

(Note - this promotion would not cost members anything and could result in more downloads of your apps!)

Brad!

CFormView as Main View

$
0
0
Is it possible to use a CFormView as the main view without using document support. IE pointing CWinApps m_pMainWnd to the CFrameWnd derived MainFrame and attaching the CFormView from there. It does not seem to be working and I was wondering before I waste any more time on the solution if it is even possible. I know it is an easy solution if I create a true SDI application however I have no use for documents in this application.

CButton surrounded with a red line

$
0
0
Hi all

i am trying to do a button with red line around it, i don't know exactly how do it.

i am understanding i need to take the DC with GetDC and i have to use a pen,
but i cannot see any red line.
Can somebody show me how do it?

Thanks in advance.

Giovanni
Viewing all 3027 articles
Browse latest View live


Latest Images