C++ Builder XE8 安卓开发之获取WIFI状态

一、首先在工程选项那里设置获取WIFI的权限,如图:



不然会出现信息为

java.lang.SecurityException:
WifiService:Neither user 10065
nor current process has
android.permission.
ACCESS_WIFI_STATE.

的对话框。


二、包含以下头文件:

#include <Androidapi.JNI.Net.hpp>
#include <Androidapi.Helpers.hpp>
#include <Androidapi.JNI.JavaTypes.hpp>
#include <Androidapi.JNI.GraphicsContentViewText.hpp>
#include <Androidapi.JNIBridge.hpp>


三、上例程

//---------------------------------------------------------------------------

#include <fmx.h>
#pragma hdrstop

#include "Unit2.h"
#include <Androidapi.JNI.Net.hpp>
#include <Androidapi.Helpers.hpp>
#include <Androidapi.JNI.JavaTypes.hpp>
#include <Androidapi.JNI.GraphicsContentViewText.hpp>
#include <Androidapi.JNIBridge.hpp>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
	_di_JObject WifiManagerObj;
	_di_JWifiManager WifiManager;
	_di_JWifiInfo WifiInfo;

	WifiManagerObj = SharedActivityContext()->getSystemService(TJContext::JavaClass->WIFI_SERVICE);

	if( WifiManagerObj !=NULL )
	{
		WifiManager = TJWifiManager::Wrap( static_cast<_di_ILocalObject>(WifiManagerObj)->GetObjectID());
		WifiInfo = WifiManager->getConnectionInfo();
		Memo1->Lines->Add(JStringToString(WifiInfo->getSSID()));        //显示SSID
		Memo1->Lines->Add(JStringToString(WifiInfo->getMacAddress()));  //显示手机MAC地址
	}
}
//---------------------------------------------------------------------------


四、_di_是什么意思?

JObject / JWifiManager / JWifiInfo 是 Delphi 的接口 。

 _di_JObject / _di_JWifiManager / _di_JWifiInfo 是C++的接口。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C++Builder XE6可以使用OpenSSL库进行AES加密,并且支持设置偏移量(IV)。以下是一个示例代码: ```c++ #include <openssl/aes.h> #include <cstring> // 加密函数 void aes_encrypt(const unsigned char *plaintext, int plaintext_len, const unsigned char *key, const unsigned char *iv, unsigned char *ciphertext) { AES_KEY aes_key; AES_set_encrypt_key(key, 128, &aes_key); AES_cbc_encrypt(plaintext, ciphertext, plaintext_len, &aes_key, iv, AES_ENCRYPT); } // 解密函数 void aes_decrypt(const unsigned char *ciphertext, int ciphertext_len, const unsigned char *key, const unsigned char *iv, unsigned char *plaintext) { AES_KEY aes_key; AES_set_decrypt_key(key, 128, &aes_key); AES_cbc_encrypt(ciphertext, plaintext, ciphertext_len, &aes_key, iv, AES_DECRYPT); } int main() { const unsigned char *plaintext = (unsigned char *)"Hello World!"; const unsigned char *key = (unsigned char *)"0123456789abcdef"; const unsigned char *iv = (unsigned char *)"1234567890abcdef"; unsigned char ciphertext[16]; unsigned char decryptedtext[16]; // 加密 aes_encrypt(plaintext, strlen((char *)plaintext), key, iv, ciphertext); // 解密 aes_decrypt(ciphertext, 16, key, iv, decryptedtext); // 输出结果 printf("Plaintext: %s\n", plaintext); printf("Ciphertext: "); for (int i = 0; i < 16; i++) printf("%02x", ciphertext[i]); printf("\nDecryptedtext: %s\n", decryptedtext); return 0; } ``` 在这个示例中,我们使用了`AES_set_encrypt_key`和`AES_set_decrypt_key`函数设置加密和解密所需的密钥,使用`AES_cbc_encrypt`函数进行加密和解密,并且传入了偏移量(IV)。注意,偏移量的长度必须与块长度相同,对于AES-128算法,块长度为128位,偏移量长度也为128位。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值