Quantcast
Channel: Visual C forum
Viewing all 15302 articles
Browse latest View live

__property keyword in C++

$
0
0

What is a correct expression for declaring properties on VC++ ( Visual Studio Express 2012 ) ?

I try to define an equivalent expression that I use on Borland C++Builder, example :

#pragma pack(push,1)
typedefunsigned __int8 Byte;
typedefunsigned __int16 Word;
typedefunsigned int UINT;

staticconst Byte // gates of TFlags32
_bg0= 1,
_bf1= 1 << 1,
_bf2= 1 << 2;

structTFlags32
{
union{
struct {
Bytef0,f1,f2,f3;
};
struct {
WordwL,wH;
};
UINTFlags;
};
//------| properties ..
boolGetN0Bit() { return f0 & _bg0; }
voidSetN0Bit(bool Bit) { Bit ? f0 |= _bg0 : f0 &=~_bg0; }
boolGetN1Bit() { return (f0 & _bf1)!=0; }
voidSetN1Bit(bool Bit) { Bit ? f0 |= _bf1 : f0 &=~_bf1; }
boolGetN2Bit() { return (f0 & _bf2)!=0; }
voidSetN2Bit(bool Bit) { Bit ? f0 |= _bf2 : f0 &=~_bf2; }
// published ..
/* error codes on compilation: C4980, C3813, C2065 
__property bool fN0 = { read = GetN0Bit, write = SetN0Bit };
__property bool fN1 = { read = GetN1Bit, write = SetN1Bit };
__property bool fN2 = { read = GetN2Bit, write = SetN2Bit };
*/
};
#pragmapack(pop)




Excel COM operations

$
0
0
I have a question about Excel COM operations.
In the example below, 

https://support.microsoft.com/en-us/kb/216686

The AutoWrap() function accepts variable length arguments, so I can set additional parameters for
DISPATCH_PROPERTYPUT or DISPATCH_PROPERTYGET operations.

However, in the example below (this is Word example, but I think it is same as Excel)
https://msdn.microsoft.com/en-us/library/vstudio/hh279683(v=vs.120).aspx

PutPropertyByName() and GetPropertyByName() method with CComPtr do not accept variable length arguments.

My question is,
If a property that I want to get or put requires more parameters, do I have to use AutoWrap() method?
or is there any way that I can do it by CComPtr Smart Pointers?

VS 2013 build win32 project cannot open 'kernel32.lib'

$
0
0

I just started using VS. And I only want to use it for C programming. So I only ticked  VC++ when I installed it.

After I created a win32 project, I added a C source file and coded a test program. But when I tried to build and run it, it gave the warning that 'Could not find WindowsSDKDir variable from the registry.' and the error 'cannot find file 'kernel32.lib''. I know it must be the issue of paths. I even tried to recovery VS and download an extra SDK for VS 2013. It didn't work. I checked the directory. The include path and library path are as follows:  path (VC_IncludePath);$(WindowsSDK_IncludePath);$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);

there are folders Microsoft SDKS/Windows/...  Microsoft Visual Studio 12.0/DIA SDK/..  Microsoft Visual Studio 12.0/SDK/.. Microsoft Visual Studio 12.0/VC/lib..  But I couldn't find kernel32.lib.

And I think if everything was installed correctly. It should be set up properly by default.  

So I'm wondering if I did wrong when I installed it. It did give me warnings saying some certificates are invalid after the installation finished. However, I don't think it does matter to functionality.. 

What should I do to remedy this? And as a newbie to VS I don't know the rules to edit paths. It's not as easy as VC++.

Appreciate it if anyone can help me. Otherwise I have to back to VC++.. 

function using Functor defined in Dll

$
0
0

Hello, I have been trying to define a function in dll and use functor (also defined in Dll).  So far, I can make the functor & use it in main.  I can define a function in Dll (it compile) that uses the functor. However, I can not use the function that uses the functor defined in dll.  It gave me error saying error LNK2019 unresolved external symbol"public static double_cdel......."  What am I doing wrong here?  Any help will be greatly appreciated.    

I attach the code

///////dll header file

#include <functional>

namespace EK1 {
class SUM2{
public:
double operator()(double a, double b, double c){
for (int i = 0; i < 10; i++){
a = a + 1.5;
}
return a + b + c;
}
};
class SUM3{
public:  _declspec(dllexport)double operator()(double a, double b, double c);
};

class GuseF{
public:template<typename T1>
  static _declspec(dllexport)double doMath(double* arr, T1 F);
};
}

////////dll cpp file

#include "EK1.h"
namespace EK1 {

double SUM3::operator()(double a, double b, double c){
for (int i = 0; i < 10; i++){
a = a + 1.5;
}
return a + b + c;
}

template<typename T1>
double GuseF::doMath(double* arr, T1 F){
int x = F(arr[0], arr[1], arr[2]);
return x;
}

}

////main.cpp

 #include "Header.h"
#pragma once
#include <iostream>
#include "EK1.h"

//this works
template<typename Funcof3>
double doMath(double* arr, Funcof3 F){
int x = F(arr[0], arr[1], arr[2]);
return x;
}

int main(){


EK1::SUM2 asd;
//this Functor defined in dll header works 
std::cout << asd(1, 2, 3) << std::endl;
//this Functor defined in dll works 
EK1::SUM3 asd1;
std::cout << asd1(4, 5, 6) << std::endl;

std::cout << "using Functor" << std::endl;

double* testvec = new double[3];
testvec[0] = 7;
testvec[1] = 8;
testvec[2] = 9;
//function defined above using functor (WORKS)
std::cout << doMath(testvec, asd1)<<std::endl;

EK1::SUM3 asd2;
//same function defined in Dll does not work(FAIL Here)
std::cout << EK1::GuseF::doMath(testvec, asd2) << std::endl;
 
system("PAUSE");
}

 


OutputPath property is not set for project xxx.vcxproj

$
0
0

I installed VS 2013 after using VS2010 Express for some time and tried to convert one of my projects.  However, I cannot even start a build due to the error:

Error    1    error : The OutputPath property is not set for project 'xxxxx.vcxproj'.  Please check to make sure that you have specified a valid combination of Configuration and Platform for this project.  Configuration='Debug'  Platform='Win32'.  This error may also appear if some other project is trying to follow a project-to-project reference to this project, this project has been unloaded or is not included in the solution, and the referencing project does not build using the same or an equivalent Configuration or Platform.    C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets    617    5    xxxxx

I have tried looking at the many similar questions and nothing seems to apply for my project.  For example there is no "Any CPU".  I have added an OutputPath to my Debug and Release builds but that made no difference whatsoever.  This project has no other project dependencies.

I have spent way too many hours for something that should never happen when converting a project.  If there were a means to append the .vcxproj file I would.

How to add ProgressBar in VC++ MFC ?

$
0
0

How to add ProgressBar at the stage of Processing some methods in Thread.

i want to show loading image while processing that's why i need to add progress bar while running the thread.

when i click the start button the Thread will start (at this time i want to show progress bar at center of the screen. just like Visual Studio opening it'll show rectangular box with progress bar and some text).

How to achieve it..?

Visual studio 2013 Migration : Cannot open include file: 'dxerr8.h': No such file or directory

$
0
0

I wrote a VC++ application in Visual Studio 2003 which uses DirectX lib using "dxerr8.h" in my applcation to provide traces for directX messages.

I can find the file in the following path

"C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\dxerr8.h"

Now i am migrating my application to Visaul Studio 2013 which throws a compilation error

Cannot open include file: 'dxerr8.h': No such file or directory

I searched for the file in the Visual Studio 2013 installed folder, which is missing.

"C:\Program Files\Microsoft Visual Studio 12.0\VC"

  1. Where is the PlatformSDK folder ?
  2. Do i need to install the DirectX SDK to get rid of this error ?

How to clear this problem ?

Extra info :

using IDirectSound & IDirectSoundBuffer Interfaces which needs "dsound.h" header file.

using DXTRACE_ERR( TEXT("DirectSoundCreate8"), hr ) which needs"dxerr8.h" header file


Exception while trying to pass CLongBinary class to stored procedure via recordset.

$
0
0

Hi,

For the last few days I’m trying to call a stored procedure within a c++ recordset.

The issue arise when I’m passing CLongBinary field threw that recordset, and then I get: ‘count field incorrect or syntax error’.

Attaching cpp recordset code for your review:

sp_insertSesMessageStore::sp_insertSesMessageStore(CDatabase* pdb)

       : CRecordset(pdb)

{

       // Param Init

       m_RETURN_VALUE = -1;

       m_PROVIDER_IDParam = _T("");

       m_BRANCH_IDParam = _T("");

       m_ACCOUNTParam = _T("");

       m_SES_USER_UNIQUE_IDParam = _T("");

       m_DISPLAY_NAMEParam = _T("");

       m_SMTP_ADDRESSParam = _T("");

       m_MESSAGE_TYPE_IDParam = 0;

       m_PRIORITYParam = 0;

       m_SUBJECTParam = _T("");

       m_SUMMARYParam = _T("");

       m_TEMPLATE_IDParam = _T("");

       m_BODY_TYPE_IDParam = 0;

       m_TRACKING_IDParam = _T("");

       m_EXPIRATION_TIMEParam = _T("");

       m_SUBCATEGORY_IDParam = 0;

       m_FOLDER_IDParam = 0;

       m_NUM_ATTACHMENTSParam = 0;

       m_ACCESS_IDParam = _T("");

       m_FLAGSParam = 0;

       m_FAVORITEParam = FALSE;

       m_CERTIFIED_IDParam = _T("");

       m_SECURE_RESPONSE_OTPParam = _T("");

       m_MESSAGE_IDParam = _T("");

       m_nParams = 24;

       m_nDefaultType = snapshot;

}

CString sp_insertSesMessageStore::GetDefaultConnect()

{

       return "";//ODBC_DSN_INFO;

}

CString sp_insertSesMessageStore::GetDefaultSQL()

{

       return _T("{CALL sp_insertSesMessageStore (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");

}

void sp_insertSesMessageStore::DoFieldExchange(CFieldExchange* pFX)

{

       // RFX input param mapping

       pFX->SetFieldType(CFieldExchange::inputParam);

       RFX_Text(pFX, _T("[@PROVIDER_ID]"), m_PROVIDER_IDParam, 3);

       RFX_Text(pFX, _T("[@BRANCH_ID]"), m_BRANCH_IDParam, 50);

       RFX_Text(pFX, _T("[@ACCOUNT]"), m_ACCOUNTParam, 255);

       RFX_Text(pFX, _T("[@SES_USER_UNIQUE_ID]"), m_SES_USER_UNIQUE_IDParam, 8);

       RFX_Text(pFX, _T("[@DISPLAY_NAME]"), m_DISPLAY_NAMEParam, 255);

       RFX_Text(pFX, _T("[@SMTP_ADDRESS]"), m_SMTP_ADDRESSParam, 255);

       RFX_Int(pFX, _T("[@MESSAGE_TYPE_ID]"), m_MESSAGE_TYPE_IDParam);

       RFX_Byte(pFX, _T("[@PRIORITY]"), m_PRIORITYParam);

       RFX_Text(pFX, _T("[@SUBJECT]"), m_SUBJECTParam, 255);

       RFX_Text(pFX, _T("[@SUMMARY]"), m_SUMMARYParam, 255);

       RFX_Text(pFX, _T("[@TEMPLATE_ID]"), m_TEMPLATE_IDParam, 255);

       RFX_Int(pFX, _T("[@BODY_TYPE_ID]"), m_BODY_TYPE_IDParam);

       RFX_Text(pFX, _T("[@TRACKING_ID]"), m_TRACKING_IDParam, 255);

       RFX_Text(pFX, _T("[@EXPIRATION_TIME]"), m_EXPIRATION_TIMEParam, 16);

       RFX_Int(pFX, _T("[@SUBCATEGORY_ID]"), m_SUBCATEGORY_IDParam);

       RFX_Int(pFX, _T("[@FOLDER_ID]"), m_FOLDER_IDParam);

       RFX_Int(pFX, _T("[@NUM_ATTACHMENTS]"), m_NUM_ATTACHMENTSParam);

       RFX_LongBinary(pFX, _T("[@BODY]"), m_BODYParam);

       RFX_Text(pFX, _T("[@ACCESS_ID]"), m_ACCESS_IDParam, 255);

       RFX_Long(pFX, _T("[@FLAGS]"), m_FLAGSParam);

       RFX_Bool(pFX, _T("[@FAVORITE]"), m_FAVORITEParam);

       RFX_Text(pFX, _T("[@CERTIFIED_ID]"), m_CERTIFIED_IDParam, 100);

       RFX_Text(pFX, _T("[@SECURE_RESPONSE_OTP]"), m_SECURE_RESPONSE_OTPParam, 50);

       //// RFX input_output param mapping

       pFX->SetFieldType(CFieldExchange::inoutParam);

       RFX_Text(pFX, _T("[@MESSAGE_ID]"), m_MESSAGE_IDParam, 8);

}

void sp_insertSesMessageStore::Move(long lRows, WORD wFetchType)

{

       m_bBOF = m_bEOF = TRUE; // By pass CRecordset

}

BOOL sp_insertSesMessageStore::ExecDirect()

{

       return Open(CRecordset::forwardOnly, NULL, CRecordset::executeDirect);

}

I’m using ExecDirect to call the stored procedure.

Is it even possible to pass the CLongBinary to a stored procedure?! If yes what am I doing wrong?

If not what are my alternatives?

Attaching the stored procedure code:

CREATE  PROCEDURE sp_insertSesMessageStore

(

@PROVIDER_ID char(3),

@BRANCH_ID varchar(50),

@ACCOUNT varchar(255),

@SES_USER_UNIQUE_ID bigint,

@DISPLAY_NAME varchar(255),

@SMTP_ADDRESS varchar(255),

@MESSAGE_TYPE_ID smallint,

@PRIORITY tinyint,

@SUBJECT varchar(255),

@SUMMARY varchar(255),

@TEMPLATE_ID varchar(255),

@BODY_TYPE_ID smallint,

@TRACKING_ID varchar(255),

@EXPIRATION_TIME datetime,

@SUBCATEGORY_ID smallint,

@FOLDER_ID smallint,

@NUM_ATTACHMENTS smallint,

@BODY varbinary(max),

@ACCESS_ID varchar(255),

@FLAGS int,

@FAVORITE bit,

@CERTIFIED_ID varchar(100),

@SECURE_RESPONSE_OTP varchar(50),

@MESSAGE_ID bigint output

)

as

begin

       select  @MESSAGE_ID=  max(MESSAGE_ID)+from SES_MessageStore

       IF @MESSAGE_ID is null

       BEGIN

              set @MESSAGE_ID = 1

       END

             

     insert into SES_MessageStore values(@MESSAGE_ID,'',@PROVIDER_ID,@BRANCH_ID,@ACCOUNT,

              @SES_USER_UNIQUE_ID,@DISPLAY_NAME,@SMTP_ADDRESS,@MESSAGE_TYPE_ID,@PRIORITY,

              @SUBJECT,@SUMMARY,@TEMPLATE_ID,@BODY_TYPE_ID,@TRACKING_ID,@EXPIRATION_TIME,

              @SUBCATEGORY_ID,@FOLDER_ID,@NUM_ATTACHMENTS,@BODY,

              @ACCESS_ID,@FLAGS,@FAVORITE,@CERTIFIED_ID,@SECURE_RESPONSE_OTP)          

End

I’m using ODBC driver for sql server 6.01.7601.17514

SQL server 2008 r2.

Thanks in advance,

Willy.


Drawing Bitmap on to screen using CRenderTarget::DrawBitmap and Byte Array (instead of file)

$
0
0

Hi All,

I am working with COSMCtrl in order to display maps on to the viewing window.

In the COSMCtrl, a file name is passed on to the CD2DBitmap constructor along with CRenderTarget object. But my application doesnt have image file. It will receive image data (in the form of byte array) from  a database.

Could any one please help me in finding out the solution ?

The sample code is below:

BOOL COSMCtrl::DrawTile(CRenderTarget* pRenderTarget, const CD2DRectF& rTile, int nTileX, int nTileY)
{
  //What will be the return value from this function (assume the worst)
  BOOL bSuccess = FALSE;

  //Form the path to the cache file which we want to draw
  int nZoom = static_cast<int>(m_fZoom);
  CString sFile(GetTileCachePath(m_sCacheDirectory, nZoom, nTileX, nTileY, FALSE));

  //Get the fractional value of the zoom
  double fInt = 0;
  double fFractionalZoom = modf(m_fZoom, &fInt);

  //Try to obtain the standard tile
  CD2DBitmap bitmap(pRenderTarget, sFile);

// I have a Byte Array. I should pass the byte array instead of file

  //Determine how the tile should be draw
  BOOL bStandardTile = FALSE;
  if (fFractionalZoom == 0 && SUCCEEDED(bitmap.Create(pRenderTarget)))
   bStandardTile = TRUE;

  //Load up the image from disk and display it if we can
  if (bStandardTile)
  {
    //Draw the image to the screen at the specified position
    pRenderTarget->DrawBitmap(&bitmap, rTile, 1.0);
    bSuccess = TRUE;
  }

return bSuccess;
}

1. I am not allowed to save the byte array to disk (as image).

2. I have tried using the other constructor of CD2DBitmap which accepts CRenderTarget and HBITMAP. but of no use

How to call C# classLibrary methods and events in C++ Console or Windows application

$
0
0

I'm working in integrating C# ClassLibrary methods into a C++ application. I have created a C++ dynamic library for importing C# methods. After that imported methods are exported to particular C++ application using _declspec(dllexport). When I compile it throws error like this.

C# Library

namespace Test
    {
        public class Class1
        {
            public int Display()
            {
                Console.WriteLine("Hai");
            }
        }
    }

C++ Wrapper Application

myFuncs.h

_declspec(dllexport) double Display();

myfuncs.cpp

MyFuncs::Display()
{
    Test::Class1 a1;
    a1.Display();
}
C++ console Application:
int main()
{
    Funcs::MyFuncs object;
    object.Display();
}  

Please help me to calling C# wrapper class and methods in (C++ windows application and also in c++ console application).

Thanks in Advance




kirubha

Comparing string with string from file

$
0
0

In my project I need to compare a text string to check the position in the file, so I can read data after that.

I made a mock file to check the compare and find functions. both does not work.

The file is UNICODE and not ANSI encrypted. Does it make a difference if so what is to be done.

My code is as follows

#include <string.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>

using namespace std;

int main(int argc, char *argv[])
{
fstream inpf;
string s, k;
string sflag = "                                INCREMENT";
size_t findit;
int inccnt = 0, chk;
inpf.open(argv[1], ios::in);
while (inpf.good())
{
getline(inpf, s);
findit = s.find(sflag);
//if (!s.compare(0, sflag.size(), sflag))
if (findit!=string::npos)
{
inccnt++;
}
}
cout << "\nTotal increments: " << inccnt << endl;
system("PAUSE");
return(0);
}


With regards, Gokul M

video

$
0
0

I was considering video for my web sites, and I have wondered a bit about content in general. Seems to be a zillion mutants of CODECs out there, and then how about working with 4K and 8K video.

I am best with Win32 but this API never was designed for such extreme video requirements.

Win32 uses AVI which also has a few problems to deal with



MSFT Signature

Place your rig specifics into your signature like I have, makes it 100x easier!

Hardcore Games Legendary is the Only Way to Play!
Vegan Advocate How can you be an environmentalist and still eat meat?

What is more handy and progressive method of creation visual programms wih C++ at the moment?

$
0
0
What library or components are used for creating GUI now, using Visual Stuido excluding .NET? I read about MFC and WTL (not much documentation) but they are pretty old and hard to learn. So i want to know what is the most coder's weapon of choice. Thank you.

Problem while accessing the GUID in a dll on 64 bit OS with 64 bit browser

$
0
0

Hi All,

I'm creating a windows service application using VS2008 (VC++), and have some executable files and dlls. And I'm registering one of the dll with "regsvr32" command. This dll contains the definition of some GUIDs for getting some unique ids of browsers installed on PCs. In 32 bit OS the functionalities are working fine, but in 64 bit OS I'm facing some issues with getting the GUIDs.

The executable files and dlls are placing in the "SysWOW64" folder and the command I'm using to register the dll is " regsvr32 C:\Windows\SysWOW64\mywork.dll ". How my application works is when we open a browser then the file "mydata.exe" will trying to find some Unique Id for this browser using the GUID in "mywork.dll" file. It is working fine with 32 bit OS for all 32 bit browsers, and 32 bit browser in 64 bit OS. When I tried this with 64 bit browsers the functionality failed with error code "zero". And the exe file "mydata.exe" is also a 32 bit build exe, it is not possible to take the 64 bit build of the exe file.

Is anything missing my project or any wrong method? Please help me to solve this issue.

Thanks in advance.

R-VR

How to add ProgressBar to Status Bar in VC++ MFC ?

$
0
0

How to add ProgressBar to Status Bar in VC++ MFC .

and show loading % at status Bar with ProgressBar


How to

$
0
0
i wrote solution wich has 3 projects in c++, then i added the 4th project written in c# in order to use a namespace that contains some classes. code generation is OK, but i could not import the classes to use them in c++. How to do? Thanks.

MoveFileEx to change name from .pdf to .PDF

$
0
0

I've found that not on all computers does rename change the extension to the case I want.

PDFCreator creates files with extensions in lower case: "Smith.pdf" for example. The unix system I'm interacting with requires upper case extension like this "Smith.PDF".

On my computer, a 64 bit Windows 7 machine, the C function rename does the job. On my clients it does not.

It seems though that

MoveFileEx ("Smith.pdf","Smith.PDF",...)

does work.

I can't find any documentation to confirm this, only my own experiments. Does anyone know if this is by design?


http://www.ransen.com Cad and Graphics software

How To Clear the Serial port buffers in Visual C++

$
0
0

Hi i am developing a windows form application using visual c++ (baudrate=115200)

any one can help me, here is my sample code

****************

private: System::Void button11_Click(System::Object^  sender, System::EventArgs^  e) 
{
String^ msg;
if(this->_serialPort->IsOpen)
{ 
this->_serialPort->Write("command");
 this->_serialPort->Write("\r\n");
msg=_serialPort->ReadExisting();
label15->Text=msg;
_serialPort->DiscardInBuffer();
_serialPort->DiscardOutBuffer();
}
}

***************************

my application need to execute the "command" it will give some result......

my problem:

the command is executing only once.. if i click the button again it is not executing the command..

I am trying to clear the buffers.. but   _serialPort->DiscardInBuffer();
 _serialPort->DiscardOutBuffer(); are not working..

please help me to execute the commands by writing it to serial port and have to read the result of the command from the serial port if click the button.

Any Help/Suggestions are very useful to me.

Thanks & Regards

Mani





CPropertySheet Embedding Question using MFC

$
0
0
Hello

  I am working on a 3D Model Viewer and am currently in the stages of making the user interface using MFC.  I'd like my property sheet to be embedded in the view and I would be greatful to know, using MFC, what is the best way to go about this.  Heres a picture of another Model viewer that uses the property sheet the way I want to.

As seen in the link.

http://img31.imageshack.us/img31/6174/modelviewer.png

Thanks

how to specify SaveAs with a default path for CFileDialog

$
0
0

I would like to set the DoModal dialog starting path to a particular default for the CFileDialog MFC class. In the constructor I can set the default extension, but how do I set the initial path to a default?

From other threads that m_pOFN points to a structure one of whose members is lpstrInitialDir. How do I set that member?

Answer: after instantiating the filedialog object, do this:

OPENFILENAME & ofn ] myFileDialog.GetOFN();

ofn.lpstrInitialIdr = L"c:\\my\\file\\path";


RT





Viewing all 15302 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>