473,385 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

2003 to 2005 upgrade - function pointer syntax issues

Hi group,

I had this with VS2003 Managed C++

pro-to-types:

===================================
TimeHandler.h

class TimeHandler
{
public:
TimeHandler(void);
virtual ~TimeHandler(void);
// Adjust time span
static bool AdjTime(TimeSpan *tsLogSpan);
};
===================================
TimeHandler.cpp

// Adjust time span
bool TimeHandler::AdjTime(TimeSpan* tsStatusLogSpan)
{
// Adjust TimeSpan here
// ...
}
===================================
Form1.h

#include "TimeHandler.h"

nanespace MyForm
{
public __gc class Form1 : public System::Windows::Forms::Form
{
static TimeSpan tsSpan = 0;
// ...

private: System::Void ShowTimeSpan_Click(System::Object * sender,
System::EventArgs * e)
{
Pass in a pointer to our TimeSpan
AdjTime ( &tsSpan );
// Display adjusted TimeSpan ...
}
};
}
===================================

And now I am trying to do the same with 2005 /clr:pure

===================================
TimeHandler.h
TimeHandler.cpp
SAME AS BEFORE
===================================
Form1.h

#include "TimeHandler.h"

namespace MyForm
{
public ref class Form1 : public System::Windows::Forms::Form
{
static TimeSpan tsStatusLogSpan = TimeSpan(0);
// ...
#pragma region Windows Form Designer generated code
/// ...
#pragma endregion
private: System::Void ShowTime_Click(System::Object^ sender,
System::EventArgs^ e)
{
Pass in a pointer to our TimeSpan
AdjTime ( &tsSpan );
// Display adjusted TimeSpan ...
}
};
}

I am getting the C2664 Error: cannot convert 'cli::interior_ptr<Type>' to
'System::TimeSpan *'
which after looking at the docs would be expected. But I still haven't found
where it shows how to fix it.

Can anyone show me what I need to change?

TIA,
Todd
Mar 6 '07 #1
4 1359
Todd R. Jacobs wrote:
I am getting the C2664 Error: cannot convert
'cli::interior_ptr<Type>' to 'System::TimeSpan *'
which after looking at the docs would be expected. But I still
haven't found where it shows how to fix it.

Can anyone show me what I need to change?
I don't have time to try it, but I believe you need to change the type of
the paramer to AdjTime to TimeSpan% instead of TimeSpan*.

-cd
Mar 6 '07 #2
Carl,

Thank you for your response.

This just arrived today
C++/CLI in Action - Using interior and pinning pointers
By Nishant Sivakumar.
http://www.codeproject.com/books/Cpp...tionCh4Ex1.asp

As described in the above article.

Changing the function definition
From:
static bool AdjTime(TimeSpan *tsLogSpan);
To:
static bool AdjTime(interior_ptr<TimeSpantsLogSpan);

Allowed the use of the native pointer &tsSpan parameter.

Is this what you were inferring?

Thanks again,
Todd

"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:uD**************@TK2MSFTNGP03.phx.gbl...
Todd R. Jacobs wrote:
>I am getting the C2664 Error: cannot convert
'cli::interior_ptr<Type>' to 'System::TimeSpan *'
which after looking at the docs would be expected. But I still
haven't found where it shows how to fix it.

Can anyone show me what I need to change?

I don't have time to try it, but I believe you need to change the type of
the paramer to AdjTime to TimeSpan% instead of TimeSpan*.

-cd


Mar 6 '07 #3
Todd R. Jacobs wrote:
Changing the function definition
From:
static bool AdjTime(TimeSpan *tsLogSpan);
To:
static bool AdjTime(interior_ptr<TimeSpantsLogSpan);

Allowed the use of the native pointer &tsSpan parameter.

Is this what you were inferring?
It looks like interior_ptr<TimeSpanwould work, too. However, Carl
recommended

static bool AdjTime(TimeSpan% tsLogSpan);

and

AdjTime(tsSpan); // instead of AdjTime(&tsSpan);

I believe this is what you are looking for -- you should just try it,
and unless you experience problems, that's the way to go.

X% is a reference, similar to X& in unmanaged code. The compiler has
more room for optimization when it comes to references, because it can
simply substitute your variable with its reference; it's not possible
with pointers. A reference is also safer than a pointer, since it must
always be initialized. A reference can't accidentally point to a random
location, or to NULL.

The advantage of interior_ptr is that you can use pointer arithmetics on
it, which as

while(*source) *dest++ = *source++;

This is not possible with references. It may also come handy that an
interior_ptr can point to nowhere, and you can also reassign it to
something else. A reference can't be reassigned to a different object.

However, it doesn't look like you need these feature. If you don't need
pointer reassignment or pointer arithmetics, you should stick with the
reference syntax.

I believe that interior_ptr is considered unsafe, and can't be used with
verifiable assemblies (in other words, places where strong security is
required, such as inside a Web browser). You should really not restrict
your function unnecessarily. Unless you have a good reason to use
interior_ptr (such as very fast image processing algorithms), you should
stick with references.

Rule of thumb: If you can solve a problem with references, do it so,
otherwise use interior_ptr.

This is just an advice, it really depends on what you need to do.

Tom
Mar 6 '07 #4
All,

Yes, that works, and I now have a better understanding of how it works
thanks too everyone's helpful advice

Thanks again,
Todd

"Tamas Demjen" <td*****@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Todd R. Jacobs wrote:
>Changing the function definition
From:
static bool AdjTime(TimeSpan *tsLogSpan);
To:
static bool AdjTime(interior_ptr<TimeSpantsLogSpan);

Allowed the use of the native pointer &tsSpan parameter.

Is this what you were inferring?

It looks like interior_ptr<TimeSpanwould work, too. However, Carl
recommended

static bool AdjTime(TimeSpan% tsLogSpan);

and

AdjTime(tsSpan); // instead of AdjTime(&tsSpan);

I believe this is what you are looking for -- you should just try it, and
unless you experience problems, that's the way to go.

X% is a reference, similar to X& in unmanaged code. The compiler has more
room for optimization when it comes to references, because it can simply
substitute your variable with its reference; it's not possible with
pointers. A reference is also safer than a pointer, since it must always
be initialized. A reference can't accidentally point to a random location,
or to NULL.

The advantage of interior_ptr is that you can use pointer arithmetics on
it, which as

while(*source) *dest++ = *source++;

This is not possible with references. It may also come handy that an
interior_ptr can point to nowhere, and you can also reassign it to
something else. A reference can't be reassigned to a different object.

However, it doesn't look like you need these feature. If you don't need
pointer reassignment or pointer arithmetics, you should stick with the
reference syntax.

I believe that interior_ptr is considered unsafe, and can't be used with
verifiable assemblies (in other words, places where strong security is
required, such as inside a Web browser). You should really not restrict
your function unnecessarily. Unless you have a good reason to use
interior_ptr (such as very fast image processing algorithms), you should
stick with references.

Rule of thumb: If you can solve a problem with references, do it so,
otherwise use interior_ptr.

This is just an advice, it really depends on what you need to do.

Tom

Mar 7 '07 #5

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

Similar topics

6
by: sathyashrayan | last post by:
Following are the selected thread from the date:30-jan-2005 to 31-jan-2005. I did not use any name because of the subject is important. You can get the original thread by typing the subject...
4
by: Spurry Moses | last post by:
I know it's in Beta 2, but I can't report any good experiences with upgrading a project form 2003 to 2005. I tried to upgrade a 2003 project to C# Express 2005. My application has hardly...
11
by: Peter Oliphant | last post by:
I've been trying all morning to convert my 2003 project (managed) to 2005 (/clr since I have both managed and unmanaged code). I'm guessing I have tens of thousands of lines of code to change. Did...
4
by: Shawn | last post by:
Hi. When I started using VS.NET 2003 there was no problem upgrading all my projects to VS.NET 2003 Framework 1.1. Everything worked as it used to under framework 1.0. Is it easy to upgrade from...
11
by: Neil | last post by:
We are running SQL 7, using Access 2000 as a front end. Our network person is wanting to migrate to Windows 2003 (we're currently on Windows 2000), and wants to know if we should migrate to SQL...
52
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server...
5
by: cj | last post by:
In 2003 I had Public Class Form1 Inherits System.Windows.Forms.Form In 2005 I've seen it with and without the Inherits System.Windows.Forms.Form. Is it supposed to be there? I'm wondering...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.