473,804 Members | 3,153 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cast problem

cdg
I am trying to write a section of code that uses a worker thread and
would need a "post message" to post a
"long" integer to the receiving function. However, I am not sure how to
write the cast for the "long" int. Apparently,
the "long" needs to be a pointer since the thread was passed the "this"
pointer for the main dialog. And the "long" is declared in the main dialog
class. If it is declared as a local variable, there is an Assertion Error
after the program is compiled, and a "Start" button is pushed. This button
starts the thread.

So, could anyone correctly write the "cast" statement that would be
needed for this post message. My C++ is not that versatile yet. And I'm
still learning how to use pointers and cast in most situations.

-----------------------------------------
error C2440: 'type cast' : cannot convert from 'long CThreadTestDlg: :*' to
'long'
-----------------------------------------

The worker thread section of code:

UINT CThreadTestDlg: :Thread1(LPVOID lParam)
{
CThreadTestDlg* pDlg = (CThreadTestDlg *)lParam;

ActxPrg m_ActxPrg; //object declaration

m_ActxPrg.Open( ); // open ActxPrg

lResult = m_xActxPrg.MemF unction();

m_ActxPrg.Close (); // close ActxPrg

pDlg->PostMessage(UW M_THREAD_FINISH ED, (WPARAM)0, (LPARAM) lResult);

return 0;
}
Jun 16 '06 #1
5 1639
cdg wrote:
I am trying to write a section of code that uses a worker thread and
would need a "post message" to post a
"long" integer to the receiving function. However, I am not sure how to
write the cast for the "long" int. Apparently,
the "long" needs to be a pointer since the thread was passed the "this"
pointer for the main dialog. And the "long" is declared in the main dialog
class. If it is declared as a local variable, there is an Assertion Error
after the program is compiled, and a "Start" button is pushed. This button
starts the thread.

So, could anyone correctly write the "cast" statement that would be
needed for this post message. My C++ is not that versatile yet. And I'm
still learning how to use pointers and cast in most situations.

-----------------------------------------
error C2440: 'type cast' : cannot convert from 'long CThreadTestDlg: :*' to
'long'
-----------------------------------------

The worker thread section of code:

UINT CThreadTestDlg: :Thread1(LPVOID lParam)
{
CThreadTestDlg* pDlg = (CThreadTestDlg *)lParam;

ActxPrg m_ActxPrg; //object declaration

m_ActxPrg.Open( ); // open ActxPrg

lResult = m_xActxPrg.MemF unction();

m_ActxPrg.Close (); // close ActxPrg

pDlg->PostMessage(UW M_THREAD_FINISH ED, (WPARAM)0, (LPARAM) lResult);

return 0;
}


You don't give us all the information we need. Where is the error
happening? On which line, and if it's on the PostMessage call, what are
the types that PostMessage() expects, and what is the type of each of
the identifiers on that line?

Please note that we don't deal with threading issues here because they
are not (yet) part of Standard C++ language and libraries. For that
reason, you may want to post in a group more applicable to your
platform or compiler. See this FAQ for what is on-topic here and for a
list of possible other groups:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

Cheers! --M

Jun 16 '06 #2
cdg
I believe that this is more of a C++ issue, it just happens to be in
another thread. But the problem is probably just writing a "cast" statement
to convert this:

'long CThreadTestDlg: :*' to 'long'

I think this will take care of the problem. However, I am not sure how to
write this type of statement.
Jun 16 '06 #3
cdg wrote:
I believe that this is more of a C++ issue, it just happens to be in
another thread. But the problem is probably just writing a "cast"
statement to convert this:

'long CThreadTestDlg: :*' to 'long'

I think this will take care of the problem. However, I am not sure
how to write this type of statement.


This operation is not guaranteed to succeed. A pointer to member can
require more room in memory than a 'long'.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 16 '06 #4
cdg wrote:
I believe that this is more of a C++ issue, it just happens to be in
another thread. But the problem is probably just writing a "cast"
statement to convert this:

'long CThreadTestDlg: :*' to 'long'

I think this will take care of the problem. However, I am not sure
how to write this type of statement.


On a second thought, make sure you don't forget the parentheses after
the name of the member function.

struct CThreadTestDlg {
long blah() { return 42L; }
};

int main() {
CThreadTestDlg d;
long lo = d.blah; // error similar to what you have
}

Oops... Actually meant

long lo = d.blah();

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 16 '06 #5
cdg
I believe that the problem I am having with this worker thread from the
previous post, is just a class access problem now. And the statements
attempting to access the member functions of this ActiveX class are not
written correctly.
The specifics for this controller function are, it is a static-private
controller thread function of the main dialog class. And I need to access
another class's member function. I have tried creating an object from the
other class, but it causing an Assertion Failure error. So, there must be a
correct way to write this class member access statement.
This statement below is what I have tried, but it does not access the
member function.

m_ActxCtrl.Open (); // open ActxCtrl
Jun 16 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1414
by: Daylor | last post by:
first of all , PLEASE,say somthing..about my post. any reply will be nice to read. i have vb.app , with 2 appdomains. (now, in the next section , ill write "appdomain create" ,means a code in the appdomain is creating ) appdomain2 call appdomain 1 to create object of type "CCar" (the param is string ) the appdomain1 creating a object from assembly file. ( the object is of
6
1823
by: Raj | last post by:
I have a c# program in which I used cast. That worked perfectly on .Net platform 1.0. When I moved to .Net 2003, I am getting the execption "Specified cast is not valid". I have not made any changes to the code. Is there any difference in project settings or something else between v1.0 and v1.1? Thanks in advance. -- Raj
0
1679
by: A. W. Dunstan | last post by:
I'm porting some code to Visual C++ and have run into a problem - the compiler won't use a user-written cast operator. The code uses an envelope-letter approach to passing (potentially) large pieces of data around, and requires that certain methods return an Envelope with a specific kind of Letter as it's content. I have a cast operator that converts from what I've got to what should be returned, but it seems that the compiler only...
3
16586
by: Mike | last post by:
I am using MS-Access as a front end for my MS-SQL DB. I have a sql view that uses the following: SELECT TOP 100 PERCENT RECID, PATNUMBER AS , SVCCODE AS , QTY, PROF_CHRGS AS , AMOUNT, BILLDATE AS , CHKAMT AS , PSDATE AS , POSTDATE AS , TRNSCODE AS , TRLR AS , SUBSTRING(CAST(SVCCODE AS varchar), 1, 4) AS FROM dbo.PAT_Transactions ORDER BY PATNUMBER, SVCCODE
36
6697
by: MSG | last post by:
The answer is neither. Use macros. #define ALLOC(size, type) ((type) *) malloc((size) * sizeof(type)) #define NEW(type, name, size) (type) * (name) = ALLOC((size), (type)) They are both type-safe and concise. Compare: NEW(int, x, 1000);
17
2680
by: Hazz | last post by:
In this sample code of ownerdraw drawmode, why does the '(ComboBox) sender' line of code need to be there in this event handler? Isn't cboFont passed via the managed heap, not the stack, into this cboFont_DrawItem event handler? Why does it need to be cast? -hazz ,................. cboFont.Items.AddRange(FontFamily.Families); } private void cboFont_DrawItem(object sender,
0
1687
by: Alan Z. Scharf | last post by:
Win Server 2003 VS.Net 2003 --------------- 1. I'm having the same problem below on all six of my pages with a datagrid item. 2. These pages all worked fine for months until problem started. 3. Same problem on two different computers running Win 2003.
5
3446
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
3
1700
by: Mike Cooper | last post by:
Hello All! I am getting teh above error message on the following code: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim dgt As DataGridTableStyle = Main_DataGrid.TableStyles(0) Dim cm As CurrencyManager = CType(Me.BindingContext _
2
4302
by: =?Utf-8?B?Unlhbg==?= | last post by:
Hi, How can I get around runtime error that says I can not explicit cast List<SubClassto ICollection<Class>? Generic List inhertis generic ICollection and Subclass inherits Class, then should not a problem to cast it explicitly, right?
0
9587
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7623
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3827
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.