ログイン
ユーザ名:

パスワード:


パスワード紛失

新規登録
メインメニュー
フォーラム一覧   -   トピック一覧
   AIR for PC
     WindowsタブレットでANEを使いGPSの情報取得
投稿するにはまず登録を

スレッド表示 | 新しいものから 前のトピック | 次のトピック | 下へ
投稿者 トピック
timai
投稿日時: 2015-5-28 11:13
一見さん
登録日: 2015-5-28
居住地:
投稿: 1
WindowsタブレットでANEを使いGPSの情報取得
お世話になります。

WindowsタブレットでANEを使いGPSの情報を取得しようとしています。

MSのサンプルを元に試しているのですが、サンプルをEXEでビルドして
確認するとGPSの状態が取得できますが、DLLとしてビルドしてANEを作成すると
OnStatusChangedのREPORT_INITIALIZINGで止まってしまい値の取得ができません。

ちなみに同期形式でのサンプルはEXEでもDLLでも値を取得できています。
以下は非同期に値を取得するサンプルを参考にしています。

参考ソース
https://msdn.microsoft.com/ja-jp/library/windows/desktop/dd317735(v=vs.85).aspx

C++を理解できていないことは十分承知していますが、どなたかご教示の程よろしくお願い致します。

開発環境は以下となります。
Windows7 SP1 64bit
VisualStudio2013
Flash Builder4.7
Apache Flex 4.11.0 FP 12.0 AIR 4.0 en_US

--ソース--
#include <string.h>
#include "LocationCallback.h" // This is our callback interface that receives Location reports.
#include <windows.h>
#include <atlbase.h>
#include <atlcom.h>
#include <LocationApi.h> // This is the main Location API header
#include "FlashRuntimeExtensions.h"
#pragma comment(lib, "locationapi.lib")
#pragma warning(disable : 4996)

extern "C"
{
__declspec(dllexport) void ExtInitializer(void** extData, FREContextInitializer* ctxInitializer, FREContextFinalizer* ctxFinalizer);
__declspec(dllexport) void ExtFinalizer(void* extData);
}

//class CInitializeATL : public CAtlExeModuleT<CInitializeATL>{};
//CInitializeATL g_InitializeATL; // Initializes ATL for this application. This also does CoInitialize for us
class CInitializeATL : public CAtlDllModuleT<CInitializeATL>{};
CInitializeATL g_InitializeATL; // Initializes ATL for this application. This also does CoInitialize for us


#define GET_GPS_TIME "get"

FREContext dllContext;
FREObject result;

// 関数宣言
FREObject getGpsTime(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]);

PCWSTR GUIDToString(REFGUID guid, PWSTR psz, UINT cch)
{
StringFromGUID2(guid, psz, cch);
return psz;
}

char resultChar[100]; // GPS取得情報文字列

FREObject getGpsTime(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]){

const uint8_t* para;
uint32_t len = strlen((const char*)argv[0]) + 1;
FREGetObjectAsUTF8(argv[0], &len, ¶);
HRESULT hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
CComPtr<ILocation> spLocation; // This is the main Location interface
CComObject<CLocationEvents>* pLocationEvents = NULL; // This is our callback object for location reports
IID REPORT_TYPES[] = { IID_ILatLongReport }; // Array of report types of interest. Other ones include IID_ICivicAddressReport

HRESULT hr = spLocation.CoCreateInstance(CLSID_Location); // Create the Location object

if (SUCCEEDED(hr))
{
hr = CComObject<CLocationEvents>::CreateInstance(&pLocationEvents); // Create the callback object
if (NULL != pLocationEvents)
{
pLocationEvents->AddRef();
}
}

if (SUCCEEDED(hr))
{
// Request permissions for this user account to receive location data for all the
// types defined in REPORT_TYPES (which is currently just one report)
if (FAILED(spLocation->RequestPermissions(NULL, REPORT_TYPES, ARRAYSIZE(REPORT_TYPES), FALSE))) // FALSE means an asynchronous request
{
wprintf(L"Warning: Unable to request permissions.\n");
}

// Tell the Location API that we want to register for reports (which is currently just one report)
for (DWORD index = 0; index < ARRAYSIZE(REPORT_TYPES); index++)
{
hr = spLocation->RegisterForReport(pLocationEvents, REPORT_TYPES[index], 0);
}
}

if (!strcmp((const char*)para, "C")) {
if (SUCCEEDED(hr))
{
// Wait until user presses a key to exit app. During this time the Location API
// will send reports to our callback interface on another thread.
// system("pause");

// Unregister from reports from the Location API
for (DWORD index = 0; index < ARRAYSIZE(REPORT_TYPES); index++)
{
spLocation->UnregisterForReport(REPORT_TYPES[index]);
}
}

// Cleanup
if (NULL != pLocationEvents)
{
pLocationEvents->Release();
pLocationEvents = NULL;
}

CoUninitialize();
}
}

return result;
}

STDMETHODIMP CLocationEvents::OnLocationChanged(__RPC__in REFIID reportType, __RPC__in_opt ILocationReport* pLocationReport)
{

// If the report type is a Latitude/Longitude report (as opposed to IID_ICivicAddressReport or another type)
if (IID_ILatLongReport == reportType)
{
CComPtr<ILatLongReport> spLatLongReport;

// Get the ILatLongReport interface from ILocationReport
if ((SUCCEEDED(pLocationReport->QueryInterface(IID_PPV_ARGS(&spLatLongReport)))) && (NULL != spLatLongReport.p))
{
// Print the Report Type GUID
wchar_t szGUID[64];
wprintf(L"\nReportType: %s", GUIDToString(IID_ILatLongReport, szGUID, ARRAYSIZE(szGUID)));

// Print the Timestamp and the time since the last report
SYSTEMTIME systemTime;
if (SUCCEEDED(spLatLongReport->GetTimestamp(&systemTime)))
{
// Compute the number of 100ns units that difference between the current report's time and the previous report's time.
ULONGLONG currentTime = 0, diffTime = 0;
if (TRUE == SystemTimeToFileTime(&systemTime, (FILETIME*)¤tTime))
{
diffTime = (currentTime > m_previousTime) ? (currentTime - m_previousTime) : 0;
}

m_previousTime = currentTime; // Set the previous time to the current time for the next report.
memset(strD, NULL, sizeof(strD));
sprintf(strD, "\nTimestamp: YY:%u, MM:%u, DD:%u, HH:%u, MM:%u, SS:%u, MS:%u\n",
systemTime.wYear,
systemTime.wMonth,
systemTime.wDay,
systemTime.wHour,
systemTime.wMinute,
systemTime.wSecond,
systemTime.wMilliseconds);
}

DOUBLE latitude = 0, longitude = 0, altitude = 0, errorRadius = 0, altitudeError = 0;

// Print the Latitude
if (SUCCEEDED(spLatLongReport->GetLatitude(&latitude)))
{
// wprintf(L"Latitude: %f\n", latitude);
memset(strD, NULL, sizeof(strD));
sprintf(strD, "Latitude: %f\n", latitude);
}

// Print the Longitude
if (SUCCEEDED(spLatLongReport->GetLongitude(&longitude)))
{
// wprintf(L"Longitude: %f\n", longitude);
memset(strD, NULL, sizeof(strD));
sprintf(strD, "Longitude: %f\n", longitude);
}

FILETIME ft1;
FILETIME ft2;
SystemTimeToFileTime(&systemTime, &ft1);
FileTimeToLocalFileTime(&ft1, &ft2);
FileTimeToSystemTime(&ft2, &systemTime);

memset(resultChar, NULL, sizeof(resultChar));
sprintf(resultChar, "gps@%04d%02d%02d%02d%02d%02d(JST)@%f@%f",
systemTime.wYear,
systemTime.wMonth,
systemTime.wDay,
systemTime.wHour,
systemTime.wMinute,
systemTime.wSecond,
latitude,
longitude
);
memset(strD, NULL, sizeof(strD));
memcpy(strD, resultChar, strlen(resultChar));
}
}

/* アプリへ返す */
const uint8_t* msg1 = (const uint8_t*)"get";
const uint8_t* msg2 = (const uint8_t*)resultChar;
FREDispatchStatusEventAsync(dllContext, msg1, msg2);
FRENewObjectFromUTF8(strlen(resultChar) + 1, ((const uint8_t *)resultChar), &result);

return S_OK;
}

// This is called when the status of a report type changes.
// The LOCATION_REPORT_STATUS enumeration is defined in LocApi.h in the SDK
STDMETHODIMP CLocationEvents::OnStatusChanged(__RPC__in REFIID reportType, LOCATION_REPORT_STATUS status)
{
if (IID_ILatLongReport == reportType)
{
switch (status)
{
case REPORT_NOT_SUPPORTED:
wprintf(L"\nNo devices detected.\n");
break;
case REPORT_ERROR:
wprintf(L"\nReport error.\n");
break;
case REPORT_ACCESS_DENIED:
wprintf(L"\nAccess denied to reports.\n");
break;
case REPORT_INITIALIZING:
wprintf(L"\nReport is initializing.\n");
break;
case REPORT_RUNNING:
wprintf(L"\nRunning.\n");
break;
}
}

return S_OK;
}

//***************************************************/
// Aneセットアップ
//***************************************************/
void ContextInitializer(
void* extData,
const uint8_t* ctxType,
FREContext ctx,
uint32_t* numFunctions,
const FRENamedFunction** functions
){
// 関数テーブル

*numFunctions = 1;
FRENamedFunction* func = (FRENamedFunction*)malloc(sizeof(FRENamedFunction) * (*numFunctions));
func[0].name = (const uint8_t*) "getGpsTime";
func[0].functionData = NULL;
func[0].function = &getGpsTime;
*functions = func;

dllContext = ctx;
}

void ContextFinalizer(FREContext ctx){
return; /* なにもしない */
}

__declspec(dllexport) void ExtInitializer(
void** extDataToSet,
FREContextInitializer* ctxInitializer,
FREContextFinalizer* ctxFinalizer
){
*extDataToSet = NULL; // 拡張データ, ここでは使わない
*ctxInitializer = &ContextInitializer; // イニシャライザの紐付け
*ctxFinalizer = &ContextFinalizer; // ファイナライザの紐付け
}

// アプリケーション終了時に呼ばれる, DLLからエクスポート
__declspec(dllexport) void ExtFinalizer(void* extData){
return; // なにもしない
}

スレッド表示 | 新しいものから 前のトピック | 次のトピック | トップ

投稿するにはまず登録を