DirectX DrawText doesn't work - function

I have been learning DirectX and Windows programming for a short time now. However, I have a problem with the DirectX function DrawText. Somehow it doesn't display text in the window, and cannot figure out why. Here is my code:
main.cpp
//Include's
#include"winwindow.hpp"
#include<time.h>
#include<iostream>
//main
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
c_winwindow window(hInstance,nCmdShow);
bool b_init=false;
b_init=window.init();
while(b_init){
window.clear(D3DCOLOR_XRGB(0xEF,0xEF,0xEF));
window.drawtext(0,0,L"Halo",D3DCOLOR_COLORVALUE(0xFF,0,0,0xFF));
window.display();
b_init=window.update();
}
return 0;
}
winwindow.hpp
//Include's
#include"windows.h"
#include"d3d9.h"
#include"d3dx9.h"
//c_winwindow
class c_winwindow{
private:
HWND hwnd;
MSG msg;
HINSTANCE hInstance;
int nCmdShow;
bool b_init;
static LRESULT CALLBACK Messagehandler(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
LPDIRECT3D9 lpd3d;
LPDIRECT3DDEVICE9 lpd3ddevice;
ID3DXFont *p_d3dfont;
bool initwin();
bool initdx();
public:
c_winwindow(const HINSTANCE &hInstance,int nCmdShow);
~c_winwindow();
bool init();
bool update();
void clear(D3DCOLOR clr);
void display();
void drawtext(unsigned short int,unsigned short int,LPCWSTR,D3DCOLOR);
};
winwindow.cpp
//Include's
#include"winwindow.hpp"
#include<iostream>
//c_winwindow memberfunction's
//konstruktor
c_winwindow::c_winwindow(const HINSTANCE &temphInstance,int tempnCmdShow){
hInstance=temphInstance;
nCmdShow=tempnCmdShow;
hwnd=NULL;
lpd3d=NULL;
lpd3ddevice=NULL;
b_init=false;
}
//destruktor
c_winwindow::~c_winwindow(){
PostQuitMessage(0);
hwnd=NULL;
if(lpd3d!=NULL){
lpd3d->Release();
lpd3d=NULL;
}
if(lpd3ddevice!=NULL){
lpd3ddevice->Release();
lpd3ddevice=NULL;
}
if(p_d3dfont!=NULL){
p_d3dfont->Release();
p_d3dfont=NULL;
}
}
//initwin
bool c_winwindow::initwin(){
if(!b_init){
WNDCLASS wc;
ZeroMemory(&wc,sizeof(wc));
wc.lpfnWndProc=Messagehandler;
wc.hInstance=hInstance;
wc.lpszClassName=L"wndc";
RegisterClass(&wc);
hwnd=CreateWindow(L"wndc",L"TestWindow",WS_SYSMENU,10,10,1200,800,NULL,NULL,hInstance,NULL);
if(hwnd==NULL){
std::cout << "failed to create Window!" << std::endl;
return false;
}else{
b_init=true;
ShowWindow(hwnd,nCmdShow);
return true;
}
}else{
return true;
}
}
//initdx
bool c_winwindow::initdx(){
lpd3d=Direct3DCreate9(D3D_SDK_VERSION);
if(lpd3d==NULL){
std::cout << "couldn't create direct3d Object" << std::endl;
return false;
}
D3DPRESENT_PARAMETERS params;
ZeroMemory(&params,sizeof(params));
params.SwapEffect=D3DSWAPEFFECT_FLIP;
params.hDeviceWindow=hwnd;
params.Windowed=true;
params.BackBufferWidth=1200;
params.BackBufferHeight=800;
params.BackBufferFormat= D3DFMT_A8R8G8B8;
if(FAILED(lpd3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&params,&lpd3ddevice))){
std::cout << "couldn't create direct3d device" << std::endl;
return false;
}
if(D3D_OK!=D3DXCreateFont(lpd3ddevice,22,0,FW_NORMAL,1,false,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,ANTIALIASED_QUALITY,DEFAULT_PITCH|FF_DONTCARE,L"Arial",&p_d3dfont)){
std::cout << "couldn't create font" << std::endl;
return false;
}
return true;
}
//init
bool c_winwindow::init(){
return initwin()&&initdx();
}
//update
bool c_winwindow::update(){
if(b_init){
if(GetMessage(&msg,NULL,0,0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
return true;
}else{
if(lpd3d!=NULL){
lpd3d->Release();
lpd3d=NULL;
}
if(lpd3ddevice!=NULL){
lpd3ddevice->Release();
lpd3ddevice=NULL;
}
hwnd=NULL;
b_init=false;
return false;
}
}else{
return false;
}
}
//clear
void c_winwindow::clear(D3DCOLOR clr){
lpd3ddevice->Clear(0,0,D3DCLEAR_TARGET,clr,0,0);
lpd3ddevice->BeginScene();
}
//display
void c_winwindow::display(){
lpd3ddevice->EndScene();
lpd3ddevice->Present(0,0,0,0);
}
void c_winwindow::drawtext(unsigned short int us_x,unsigned short int us_y,LPCWSTR text,D3DCOLOR textcolor){
RECT r;
SetRect(&r,us_x,us_y,0,0);
p_d3dfont->DrawText(NULL,text,-1,&r,DT_LEFT,textcolor);
}
//WndProc
LRESULT CALLBACK c_winwindow::Messagehandler(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
switch(msg){
case(WM_DESTROY):
PostQuitMessage(0);
return 0;
break;
case(WM_PAINT):
return 0;
break;
}
return DefWindowProc(hwnd,msg,wParam,lParam);
}
The window appears grey, with no text in it. Can anyone explain why there is no text?

Related

How can I get my queue in C++ work? Unhandeled Exception: Access violation reading location

I got a problem by implementing a queue in C++. I looked for similar problems, but didn't find anything usefull.
I'm using Visual Studio 2019.
I seperated my program in a Main.cpp, a Queue.h and Queue.cpp, Patient.h and Patient.cpp.
I tried to convert the concept for this from Java to C++, but I just can't find a solution for my function getInfo().
I get an exception like this:
Unhandled exception at 0x7C0EF3BE (ucrtbased.dll) in Queue.exe: 0xC0000005: Access violation reading location 0xE8884D8D.
Would be nice if anyone could help me with my problem and explain what I did wrong.
I'm just a beginner so don't be too harsh on me pls xD
Main.cpp:
#include "Queue.h"
#include "Patient.h"
int main() {
Queue queue;
Patient patient1("Name1");
Patient patient2("Name2");
queue.add(patient1);
queue.add(patient2);
queue.getInfo();
}
Queue.h:
#pragma once
#include <iostream>
#include "Patient.h"
using namespace std;
class Queue {
private:
Patient* beginning;
Patient* end;
int amount;
public:
Queue();
void add(Patient p);
Patient remove();
void getInfo();
};
Queue.cpp:
#include "Queue.h"
Queue::Queue() {
beginning = 0;
end = 0;
amount = 0;
}
void Queue::add(Patient p) {
if (amount == 0) {
beginning = &p;
end = &p;
} else {
end->setFollower(p);
end = &p;
}
amount++;
}
Patient Queue::remove() {
if (amount == 0) {
cout << "You can't remove a patient. The Queue is empty!" << endl;
} else {
*beginning = beginning->getFollower();
amount--;
}
return *beginning;
}
void Queue::getInfo() {
if (amount == 0) {
cout << "The Queue is empty!" << endl;
} else {
cout << "There are " << amount << " Patients in the Queue!" << endl;
cout << "The following list provides all Patients in the Queue-order:" << endl;
beginning->getInfo();
}
}
Patient.h:
#pragma once
#include <iostream>
#include <string>
using namespace std;
class Patient {
private:
string name;
Patient* follower;
string* nameptr;
public:
Patient(string newname);
void setFollower(Patient p);
Patient getFollower();
void getInfo();
};
Patient.cpp:
#include "Patient.h"
Patient::Patient(string newname) {
name = newname;
follower = 0;
nameptr = &name;
}
void Patient::setFollower(Patient p) {
follower = &p;
}
Patient Patient::getFollower() {
return *follower;
}
void Patient::getInfo() {
cout << *nameptr << endl;
if (follower == 0) {
cout << "No follower existing!" << endl;
}
else {
follower->getInfo();
}
cin.get();
}
There are a few places where you mix up passing by value with passing by reference.
To start with, the first problem is here:
void Queue::add(Patient p) {
if (amount == 0) {
beginning = &p;
end = &p;
} else {
end->setFollower(p);
end = &p;
}
amount++;
}
You are passing the value of Patient p rather than a reference to the actual object. To fix this you only need to add an "&" to your functional call like this:
void Queue::add(Patient& p) {
if (amount == 0) {
beginning = &p;
end = &p;
} else {
end->setFollower(p);
end = &p;
}
amount++;
}
Note the "&" in the parameters list. Then you must also update the function header:
class Queue {
private:
Patient* beginning;
Patient* end;
int amount;
public:
Queue();
void add(Patient& p);
Patient remove();
void getInfo();
};
You must also pass by reference for your setFollower function:
void Patient::setFollower(Patient& p) {
follower = &p;
}
and in the header file:
void setFollower(Patient& p);
What you need to know going forward is that in C++ all arguments are passed by value unless you specify passing by reference in the function's parameter list. Here is an article about passing variables to functions if you'd like to read more (https://iq.opengenus.org/call-by-value-vs-call-by-reference-cpp/).

Propagating exceptions in C++ Builder threads

Based on the credited answer to How can I propagate exceptions between threads?, I created a little test application to explore propagation:
#include <vcl.h>
#pragma hdrstop
#include<iostream>
#include<thread>
#include<exception>
#include<stdexcept>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
static std::exception_ptr teptr = nullptr;
static UnicodeString status;
void __fastcall f()
{
try
{
throw std::runtime_error("To be passed between threads");
} catch(...) {
teptr = std::current_exception();
if (!teptr) {
status += U"; NULL teptr";
} else {
status += U"; Non-NULL teptr";
}
}
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
std::thread mythread(f);
mythread.join();
std::this_thread::sleep_for(std::chrono::seconds(3));
if (teptr) {
status += U"; Button1Click non-NULL teptr";
try
{
std::rethrow_exception(teptr);
} catch(const std::exception &ex) {
std::cerr << L"Thread exited with exception: " << ex.what() << "\n";
}
} else {
status += U"; Button1Click NULL teptr";
}
Application->MessageBox(status.c_str(), L"Button1Click", MB_OK);
}
The results in the message box turn out to be "; NULL teptr; Button1Click NULL teptr", so to me, it looks like std::current_exception() failed to work. How can I get an application-thrown error to propagate back to the program that launched the thread?

How to use boolean function inside class in Arduino?

I am making a library for the MPR121 sensor and in that I want to use a bool function inside a class in Arduino IDE but it is not working.
Here's my code.
#include <Wire.h>
#include "Adafruit_MPR121.h"
#ifndef _BV
#define _BV(bit) (1 << (bit))
#endif
Adafruit_MPR121 cap = Adafruit_MPR121();
uint16_t lasttouched = 0;
uint16_t currtouched = 0;
class PaperTron {
private:
uint8_t i;
uint8_t a;
public:
PaperTron(){
}
void touchBegin(){
Serial.begin(9600);
Serial.println("Hi! I'm PaperTron.");
if (!cap.begin(0x5A)) {
Serial.println("Error! TOUCH pins not found. Please check wiring.");
while (1);
}
Serial.println("Hurray! Now you can use my TOUCH pins.");
}
**//This is the boolean function which is not working**
bool isHigh(uint8_t touchpin) {
currtouched = cap.touched();
for (i=0; i<12; i++) {
if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
if(i==touchpin) return true;
}
if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
if(i==touchpin) return false;
}
}
lasttouched = currtouched;
}
};
PaperTron papertron;
void setup() {
papertron.Begin();
papertron.touchBegin();
}
void loop() {
if(papertron.isHigh(2)){Serial.println("Hello");}
}
The serial monitor is showing "Hello" continuously whereas it should print "Hello" only when I press the touch pin on MPR121.

QtableView Delete selected file from Sql database

Hello guys as i am new in Qt,my problem is i want to delete the already stored images from Sql database for that i have created a delete button in my Gui, it should be like if i press the seleted file in table view should delete from database as well as disapear from tableview. For that i tried my best to make it work but it is not working. Please help.
// Database.h ///
i have defined removedRecord
public slots:
bool insertIntoTable(const QVariantList &data);
bool insertIntoTable(const QString &name, const QByteArray &pic);
bool removeRecord(const int id);
//Database.cpp //
**#include "database.h"**
DataBase::DataBase(QObject *parent) : QObject(parent)
{
}
DataBase::~DataBase()
{
}
void DataBase::connectToDataBase()
{
if(!QFile("../AIC_Data_Base/" DATABASE_NAME).exists()){
this->restoreDataBase();
} else {
this->openDataBase();
}
}
bool DataBase::restoreDataBase()
{
if(this->openDataBase()){
return (this->createTable()) ? true : false;
} else {
qDebug() << "Data Base error";
return false;
}
return false;
}
bool DataBase::openDataBase()
{
db = QSqlDatabase::addDatabase("QSQLITE");
db.setHostName(DATABASE_HOSTNAME);
db.setDatabaseName("../AIC_Data_Base/" DATABASE_NAME);
if(db.open()){
return true;
} else {
return false;
}
}
void DataBase::closeDataBase()
{
db.close();
}
bool DataBase::createTable()
{
QSqlQuery query;
if(!query.exec( "CREATE TABLE " TABLE " ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
TABLE_NAME " VARCHAR(255) NOT NULL,"
TABLE_PIC " BLOB NOT NULL"
" )"
)){
qDebug() << "DataBase: error of create " << TABLE;
qDebug() << query.lastError().text();
return false;
} else {
return true;
}
return false;
}
bool DataBase::insertIntoTable(const QVariantList &data)
{
QSqlQuery query;
query.prepare("INSERT INTO " TABLE " ( " TABLE_NAME ", "
TABLE_PIC " ) "
"VALUES (:Name, :Pic)");
query.bindValue(":Name", data[0].toString());
query.bindValue(":Pic", data[1].toByteArray());
if(!query.exec()){
qDebug() << "error insert info " << TABLE;
qDebug() << query.lastError().text();
return false;
} else {
return true;
}
return false;
}
bool DataBase::insertIntoTable(const QString &name, const QByteArray &pic)
{
QVariantList data;
data.append(name);
data.append(pic);
if(insertIntoTable(data))
return true;
else
return false;
}
bool DataBase::removeRecord(const int id)
{
QSqlQuery query;
query.prepare("DELETE FROM " TABLE " WHERE id= :ID ;");
query.bindValue(":ID", id);
if(!query.exec()){
qDebug() << "error delete row " << TABLE;
qDebug() << query.lastError().text();
return false;
} else {
return true;
}
return false;
}
Mainwindow.h
private slots:
void on_pushButton_add_clicked();
void on_screenButton_clicked();
void slotCurrentPic(QModelIndex index);
void on_Delete_Button_clicked(QModelIndex index);
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMainWindow>
#include <QDesktopWidget>
#include <QMessageBox>
#include <QFileInfo>
#include <QString>
#include <QFile>
#include <QFileDialog>
#include <QDir>
#include <QDebug>
#include <QWidget>
#include <QPixmap>
#include <QApplication>
#include <QBuffer>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// this command is used for : setting the title screen and logo.
this->setWindowTitle("AIC Tool V1.0");
setWindowIcon(QIcon(":/9982-200.png"));
db = new DataBase();
db->connectToDataBase();
this->setupModel(TABLE,
QStringList() << trUtf8("id")
<< trUtf8("Picture List")
<< trUtf8("Data_Base")
);
this->createUI();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_add_clicked()
{
QFileDialog dialog(this);
dialog.setNameFilter(tr("*.png *.gif *.jpg *.tif *.xpm"));
dialog.setViewMode(QFileDialog::Detail);
QString fileName =QFileDialog::getOpenFileName(this,tr("Open Image"),"../AIC_Incoming_Images",tr ("Image Files(*.png *.gif *.jpg *.tif *.xpm)"));
ui->label->setText(fileName);
if(!fileName.isEmpty())
{
QImage image(fileName);
int w = ui->label_newpic->width();
int h = ui->label_newpic->height();
QPixmap tasveer =QPixmap::fromImage(image);
ui->label_newpic->setPixmap(tasveer.scaled(w,h,Qt::KeepAspectRatio));
//ui->label_datapic->setPixmap(tasveer.scaled(w,h,Qt::KeepAspectRatio));
}
else {
QMessageBox::critical(this, "Error", "No file selected");
}
}
void MainWindow::setupModel(const QString &tableName, const QStringList &headers)
{
model = new QSqlTableModel(this);
model->setTable(tableName);
/* Set the columns names in a table with sorted data
* */
for(int i = 0, j = 0; i < model->columnCount(); i++, j++){
model->setHeaderData(i,Qt::Horizontal,headers[j]);
}
}
void MainWindow::createUI()
{
ui->tableView->setModel(model);
ui->tableView->setColumnHidden(0, true); // Hide the column id Records
ui->tableView->setColumnHidden(2, true); // Hide the column with image
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
ui->tableView->resizeColumnsToContents();
ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers); // editing is not allowed
ui->tableView->horizontalHeader()->setStretchLastSection(true); // Stretch the last column of around tableView
/* Connect the signal to change the selection of the current row in the table
* to the slot to set the image picLabel
* */
connect(ui->tableView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
this, SLOT(slotCurrentPic(QModelIndex)));
model->select();
}
void MainWindow::on_screenButton_clicked()
{
QFileDialog dialog(this);
dialog.setNameFilter(tr("*.png *.gif *.jpg *.tif *.xpm"));
dialog.setFileMode(QFileDialog::ExistingFiles);
dialog.setViewMode(QFileDialog::Detail);
//QPixmap inPixmap =QFileDialog::getOpenFileName(this,tr("Open Image"),"../AIC_Incoming_Images",tr ("Image Files(*.png *.gif *.jpg *.tif *.xpm)"));
//QStringList inPixmap =QFileDialog::getOpenFileNames(this,tr("Open Image"),"../AIC_Incoming_Images",tr ("Image Files(*.png *.gif *.jpg *.tif *.xpm)"));
QString filename_1 =QFileDialog::getOpenFileName(this,tr("Open Image"),"../AIC_Incoming_Images",tr ("Image Files(*.png *.gif *.jpg *.tif *.xpm)"));
QString filePath = QFileInfo(filename_1).fileName();
QImage image_1(filename_1);
QPixmap inPixmap =QPixmap::fromImage(image_1);
//QPixmap inPixmap = screen->grabWindow( 0 ); // Keeping it in the image of the object QPixmap
QByteArray inByteArray; // Create QByteArray object to save the image
QBuffer inBuffer( &inByteArray ); // Saving images produced through the buffer
inBuffer.open( QIODevice::WriteOnly ); // Open buffer
inPixmap.save( &inBuffer, "PNG" ); // Write inPixmap in inByteArray
// Write a screenshot of the database
//db->insertIntoTable(QDateTime::currentDateTime().toString("dd.MM.yyyy_hh:mm:ss.png"), inByteArray);
db->insertIntoTable(filePath, inByteArray);
model->select();
}
void MainWindow::slotCurrentPic(QModelIndex index)
{
QPixmap outPixmap = QPixmap(); // Create QPixmap, which will be placed in picLabel
/* Taking the image data from the table as QByteArray and put them in QPixmap
* */
outPixmap.loadFromData(model->data(model->index(index.row(), 2)).toByteArray());
ui->picLabel->setPixmap(outPixmap.scaled(1000,450));
m_selectedId = model->data(model->index(index.row(), 0)).toInt();
}
void MainWindow::on_Delete_Button_clicked(QModelIndex index)
{
db->removeRecord(id);
}

private C++ template function in a regular class - OpenCL

I am trying to create a customized class around the OpenCL C++ wrapper to get some specific information from the available devices. For example get the number of available GPUs, CPUs, etc. in a platform. To reduce code I decided to implement a private template function as shown below:
//Devices.hpp
class Devices
{
public:
Devices(const cl::Platform& inputPlatform)
{
inputPlatform.getDevices(CL_DEVICE_TYPE_ALL, &availableDevices);
}
cl_int getTotalNumberOfDevices()
{
return availableDevices.size();
}
cl_int getTotalNumberOfGPUs()
{
return countDevicesWithSpecificProperty(CL_DEVICE_TYPE, CL_DEVICE_TYPE_GPU);
}
private:
std::vector<cl::Device> availableDevices;
template <typename T>
cl_int countDevicesWithSpecificProperty(
const cl_device_info& deviceInfo,
const T& searchPropertyValue)
{
cl_int totalNumberOfDevices = getTotalNumberOfDevices();
T response;
cl_int count = 0;
for (cl_int i = 0; i < totalNumberOfDevices; ++i)
{
try
{
availableDevices.at(i).getInfo(deviceInfo, &response);
}
catch (cl::Error e)
{
return e.err();
}
if (response == searchPropertyValue) ++count;
}
return count;
}
};
While the code compiles correctly, getInfo throws a CL_INVALID_VALUE error. When I implemented the same code using regular function (instead of a template) the code works fine:
//Devices.hpp
class Devices
{
public:
Devices(const cl::Platform& inputPlatform)
{
inputPlatform.getDevices(CL_DEVICE_TYPE_ALL, &availableDevices);
}
cl_int getTotalNumberOfDevices()
{
return availableDevices.size();
}
cl_int getTotalNumberOfGPUs()
{
return countDevicesWithSpecificProperty(CL_DEVICE_TYPE, CL_DEVICE_TYPE_GPU);
}
private:
std::vector<cl::Device> availableDevices;
cl_int countDevicesWithSpecificProperty
(const cl_device_info& deviceInfo,
const cl_device_type& searchPropertyValue)
{
cl_int totalNumberOfDevices = getTotalNumberOfDevices();
cl_device_type response;
cl_int count = 0;
for (cl_int i = 0; i < totalNumberOfDevices; ++i)
{
try
{
availableDevices.at(i).getInfo(deviceInfo, &response);
}
catch (cl::Error e)
{
return e.err();
}
if (response == searchPropertyValue) ++count;
}
return count;
}
};
Any thoughts?
PS: The method is invoked as follows:
//main.cpp
#define __CL_ENABLE_EXCEPTIONS
#include <iostream>
#include <vector>
#include <CL/cl.hpp>
#include "Devices.hpp"
int main()
{
try
{
std::vector<cl::Platform> availablePlatforms;
cl::Platform::get(&availablePlatforms);
Devices d(availablePlatforms[0]);
std::cout << d.getTotalNumberOfGPUs() << std::endl;
}
catch (cl::Error e)
{
std::cout << e.what() << std::endl << e.err() << std::endl;
}
return 0;
}
The issue is that your response variable doesn't have the correct type in your templated version. This is because you are passing CL_DEVICE_TYPE_GPU to the templated parameter, which is a preprocessor macro, and so won't necessarily have the correct type needed for the device info query.
One solution is to explicitly cast the templated parameter to ensure it has the correct type:
return countDevicesWithSpecificProperty(CL_DEVICE_TYPE, (cl_device_type)CL_DEVICE_TYPE_GPU);
Check assembler listing for both cases. There should be some difference in what compiler generates.