|
Thank you Daniel for the thoughts.. I am exploring other option due to the order I build the .lib gives linker error...if other option does not pan out I will go with your suggestion.. This was helpful..!
|
|
|
|
|
You have declared the classes as dllimport so you must add the .lib file to your linker section in your build.
|
|
|
|
|
Thank you Richard !.. The order I am compiling the different projects(.lib) cannot be changed. First project referencing member functions from other project that was not even compiled..so other than getprocaddress() , no better option ?
|
|
|
|
|
That makes no sense at all. Build the lib project first or waste your time.
|
|
|
|
|
I think he is trying to tell you he has got a circular dependancy problem.
In vino veritas
|
|
|
|
|
How to solve circular dependency in linker is shown here
Library order in static linking - Eli Bendersky's website[^]
The trick is to organize the library files as shown and link them twice which is perfectly valid.
I assume that is the reason you are trying to avoid including the library file.
In vino veritas
|
|
|
|
|
I need to open a file for both reading/writing using fstream and read each character then write that character back to the file. for example i have this code.
fstream in("test.txt",ios::in | ios::out);
if(!in)
cout<<"error...";
else
{
char ch;
in.seekg(0,ios::end);
int end=in.tellg();
in.seekg(0); for(int i=0;i<end;i++)
{
if(!in.get(ch).fail()) {
in.seekp(static_cast<int>(in.tellg())-1); if(in.put(ch).fail()) break; }
}
}
I have a file named "test.txt" which contains "ABCD". As i understand it both put() and get() methods of the stream object move the file pointer forward(i see that by getting the return value of tellg() or tellp() functions after each get() or put() method call). My question is when i comment out the code that will seek the stream pointer to "where it is now"(in.seekg(in.tellg()), the code will result incorrect results. I don't understand why this is since tellg() is showing the correct position of the character to be read next what is the purpose of explicitly seeking to it? The incorrect result is it write to the file "ABBB" instead of "ABCD". I am using visual studio 2005.
modified 3-Apr-16 16:26pm.
|
|
|
|
|
Read the documentation
The seekp method changes the location of a stream object's file pointer for output (put or write.) In most cases, seekp also changes the location of a stream object's file pointer for input (get or read.)
See that last bit of the statement. Your code assumes you are independently moving the get and put pointers. The implementation in linux depends also on stream type and I am not sure in VS2005 so read the documentation carefully.
In later versions of Visual Studio they use different terms
seekg => The absolute position in which to move the read pointer.
seekp => The position in the stream (meaning both read and write)
You also need a stream clear() after any seekp otherwise a seek to last character of a file will cause an error .. ATE flag gets set
In vino veritas
modified 3-Apr-16 13:36pm.
|
|
|
|
|
Thanks for your replay. But the code doesn't assume the input and output pointers are independently moved. In fact,in this case, the put() method will move the input pointer and the get() method move the output pointer as it is evident by looking at the values returned from tellp() and tellg(). This is why i am confused. if the put() statement in the code moves the input file pointer to the next character( which will be read by the next iteration) why do i need to seek to it explicitly is the question.
|
|
|
|
|
First you have the input and output pointers mixed in the above
Second the put function doesn't work the way you think in the above
MSDN => The member function put (which writes a single character) is called, the character is not written directly to the physical file with which the stream is associated. Instead of that, the character is inserted in that stream's intermediate buffer.
Put in.sync() after the put
MSDN => If the streams are synchronized, a program can mix iostream operations with stdio operations, and their observable effects are guaranteed to follow the same order as used in the program.
I think you need to do some more reading on streams with the sync it will do what you expect.
In vino veritas
|
|
|
|
|
|
Happy New Month to you all.
However, l am playing with Createfile, WriteFile and ReadFile functions, Createfile and Writefile works well but my problem is ReadFile.
l want to read the data written to a buffer "szBuffer", by using "ReadFile" to read the data in the szBuffer into another buffer szBuf. But it doesn't work.
When l check the return value like error=ReadFile(hfile,szBuffer,10,&in,NULL), it returns 0 but when l use GetLastError() to check for the return value, it gives me 998. l learnt that the second parameter to ReadFile() is the address to store the data read.
Code snippet below:
<pre
lang="c++">hfile=CreateFile("C:\file.txt",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL);// this works well
<pre>
WriteFile(hfile,szBuffer,256,&in,NULL);//this works well
ReadFile(hfile,szBuf,256,&in,NULL);//this does not read data
CloseHandle(hfile);
hdc=GetDC(hwnd);
TextOut(hdc,50,300,szerror,wsprintf(szerror,"%i",GetLastError()));//check return value
ReleaseDC(hwnd,hdc);</pre>
Can someone help me to overcome this?
Thanks.
modified 4-Apr-16 9:59am.
|
|
|
|
|
After writing to the file, the file pointer is at the actual end of the file when the file has been created. If you then try to read from the file, there is nothing to read at that position (the end of the file).
If you want to read the data that has just been written, you must set the file pointer using SetFilePointer function (Windows)[^]:
SetFilePointer(hFile, 0, 0, FILE_BEGIN);
A return value of zero (FALSE ) indicates that the function failed (see ReadFile function (Windows)[^]). Error code 998 is ERROR_NOACCESS / " Invalid access to memory location."
|
|
|
|
|
Thanks. But l have made necessary corrections but the ReadFile is still not working and GetLasterror still returns 998. Also, direct check of ReadFile also returns 0. Help please.
<blockquote class="quote"><div class="op">Quote:</div>hfile=CreateFile("C:\\file.txt",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL);
<pre>
WriteFile(hfile,szBuffer,256,&in,NULL); SetFilePointer(hfile,0,0,FILE_BEGIN);
ReadFile(hfile,szBuf,256,&in,NULL); CloseHandle(hfile);
hdc=GetDC(hwnd);
TextOut(hdc,50,300,szerror,wsprintf(szerror,"%i",GetLastError())); ReleaseDC(hwnd,hdc);</blockquote></pre>
|
|
|
|
|
You should check the return value from all system calls to see whether the function succeeded or failed. Without that information you are just guessing.
|
|
|
|
|
A probable error source is szBuf being NULL .
|
|
|
|
|
Use double slashes in your file name.
ReadFile() will read from the file pointer's current position. Perhaps you need to call SetFilePointer(FILE_BEGIN) in between write and read.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I made following program to use opencl library supplied with Nvidia cuda 7.5.
As result I obtained:
Num of devices=1
Device name= quadro K600
Device vendor=NVIDIA Corporation
Device Version=OPENCL 1.2 CUDA
Driver Version= 353.90
DEVICE_MAX_COMPUTE_UNITS = 1 !!!!!!!!!!!!!!!!!!!!!!!!!!
DEVICE_MAX_CLOCK_FREQUENCY = 875 MHZ
DEVICE_GLOBAL_MEM_SIZE= 1073741824
Only 1 compute unit at 875 Mhz????
I read that K600 has 192
#include <stdlib.h>
#define __CL_ENABLE_EXCEPTIONS
#pragma warning(disable:4996)
#include <CL/cl.hpp>
#include <fstream>
#include <iostream>
#include <time.h>
#include <cmath>
#define LOCAL_SIZE 512
#define WIDTH_A (4096*2)
#define HEIGHT_A (4096*2)
float *matrix_A;
float *vector_B;
float *result_vector;
float *result_vector_host;
#define MAX_SOURCE_SIZE (0x100000)
int main()
{
cl_platform_id platform_id = NULL;
cl_device_id device_id = NULL;
cl_context context = NULL;
cl_command_queue command_queue = NULL;
cl_mem Amobj = NULL;
cl_mem Bmobj = NULL;
cl_mem Cmobj = NULL;
cl_program program = NULL;
cl_kernel kernel = NULL;
cl_uint ret_num_devices;
cl_uint ret_num_platforms;
cl_int ret;
int i, j;
ret = clGetPlatformIDs(1, &platform_id, &ret_num_platforms);
ret = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_DEFAULT, 1, &device_id, &ret_num_devices);
context = clCreateContext(NULL, 1, &device_id, NULL, NULL, &ret);
char buffer[10240];
cl_uint buf_uint;
cl_ulong buf_ulong;
printf("Num of devices=%i", ret_num_devices);
for (i = 0; i < ret_num_devices; i++)
{
printf(" -- %d --\n", i);
clGetDeviceInfo(device_id, CL_DEVICE_NAME, sizeof(buffer), buffer, NULL);
printf(" DEVICE_NAME = %s\n", buffer);
clGetDeviceInfo(device_id, CL_DEVICE_VENDOR, sizeof(buffer), buffer, NULL);
printf(" DEVICE_VENDOR = %s\n", buffer);
clGetDeviceInfo(device_id, CL_DEVICE_VERSION, sizeof(buffer), buffer, NULL);
printf(" DEVICE_VERSION = %s\n", buffer);
clGetDeviceInfo(device_id, CL_DRIVER_VERSION, sizeof(buffer), buffer, NULL);
printf(" DRIVER_VERSION = %s\n", buffer);
clGetDeviceInfo(device_id, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(buf_uint), &buf_uint, NULL);
printf(" DEVICE_MAX_COMPUTE_UNITS = %u\n", (unsigned int)buf_uint);
clGetDeviceInfo(device_id, CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof(buf_uint), &buf_uint, NULL);
printf(" DEVICE_MAX_CLOCK_FREQUENCY = %u\n", (unsigned int)buf_uint);
clGetDeviceInfo(device_id, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(buf_ulong), &buf_ulong, NULL);
printf(" DEVICE_GLOBAL_MEM_SIZE = %llu\n", (unsigned long long)buf_ulong);
}
}
modified 31-Mar-16 11:32am.
|
|
|
|
|
How is this:
printf(" DEVICE_MAX_CLOCK_FREQUENCY = %u\n", (unsigned int)buf_uint);
printing this:
DEVICE_MAX_CLOCK_FREQUENCY = 875 MHZ
Perhaps the code you are using and the code you pasted are not the same?
Have you tried asking your question here?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I edited it after reading to make it more easy to understand.
I have seen that the old video card is not very good improving the performance of the CPU.
|
|
|
|
|
I used angle arc to divide circle into 8 segments, when i extend an angle of one angle arc then the other dissappears , it does not overwrites what to do?
What I have tried:
i used the below code
MoveToEx(hMemDC,50,50 , (LPPOINT) NULL);
AngleArc(hMemDC, 50 , 50 , 47, 0, 45);
SetArcDirection(m_hMemDC, AD_CLOCKWISE);
LineTo(hMemDC,50,50);
EndPath(hMemDC);
StrokeAndFillPath(hMemDC);
then
MoveToEx(hMemDC,50,50 , (LPPOINT) NULL);
AngleArc(hMemDC, 50 , 50 , 47, 45, 45);
SetArcDirection(m_hMemDC, AD_CLOCKWISE);
LineTo(hMemDC,50,50);
EndPath(hMemDC);
StrokeAndFillPath(hMemDC);
and so on..
now if i want to increase the angle of 2nd segment to 55 degrees then the 3rd segment dissappears. how to solve it ?
|
|
|
|
|
You should decide where to ask this question...Re-posting here (after the QA) will not gain you any advantage, but maybe some who thing you are annoying them...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
Hi, Good day everyone.
l have some difficulties in the following which l need some help. Am a learner in win32 programming.
l created an application with a button "LogOut", which l want, when the user clicks the LogOut button, the application starts afresh. Just like in a standard program(eg. MSWORD) where when "New" is clicked, a new workspace pops out. So l need help in making my program to start afresh when LogOut button is clicked.
MY TRIAL:
l had done the following, and it worked but it only run the codes in WM_CREATE and l still had sent messages to other cases like WM_PAINT, WM_NOTIFY etc, still only the code in WM_CREATE runs.
case IDC_LOGOUTBTN:
SendMessage(hWnd,WM_CREATE, 0,(LPARAM)lpcs)break;
At some point in my program, l generate random numbers using srand((unsigned)time(&t)) and rand() functions when NEXT button is clicked. But l want to know if there is anyway to get the previous random number(s) when PREVIOUS button is clicked?
Thanks.
modified 30-Mar-16 3:27am.
|
|
|
|
|
Member 12139442 wrote: Just like in a standard program(eg. MSWORD) where when "New" is clicked, a new workspace pops out. Word simply creates a new document. It does not start over.
Member 12139442 wrote: So l need help in making my program to start afresh when LogOut button is clicked. I would consider ShellExecute() or CreateProcess() for this.
Member 12139442 wrote: But l want to know if there is anyway to get the previous random number(s) when PREVIOUS button is clicked? Store them in a container (e.g., array).
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
|